Download the PHP package philippgrashoff/mtomforatk without Composer
On this page you can find all versions of the php package philippgrashoff/mtomforatk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package mtomforatk
mtomforatk
An addition to atk4/data to easily manage Many To Many (MToM) Relations. The purpose is to write as little code as possible for actual MToM operations.
Project Content
The project consists of two files:
- JunctionModel: A base model for a junction class (like StudentToLesson). Working descendants can be coded with a few lines of code. Static methods to add (e.g.
StudentToLesson::addMToMRelation($student, $lesson);
), remove ((e.g.StudentToLesson::removeMToMRelation($student, $lesson);
) and check ((e.g.StudentToLesson::hasMToMRelation($student, $lesson);
) are implemented here. - MToMTrait: A Trait which is added to the models to be linked, (like Student and Lesson). With this trait, the MToM relation can be defined with a single line in Model::init():
$this->addMToMReferenceAndDeleteHook();
.
How to use
Installation
The easiest way to use this repository is to add it to your composer.json in the requirement section:
Sample code
As example, lets use Students and Lessons. A Student can have many Lessons, a Lesson can have many Students. To map this MToM relationship, 3 classes are created. Demo models for this example can be found in tests\Testmodels:
- Student: A normal model which uses MToMTrait.
- Lesson: A normal model which uses MToMTrait.
- StudentToLesson: The junction model carrying the student_id and lesson_id for each MToM relation between Students and Lessons.
After setting these classes up using this project, MToM operations can be done easily:
The sample code from this readme can be found in the docs
directory.
Versioning
The version numbers of this repository correspond with the atk4\data versions. So 4.0.x is compatible with atk4\data 4.0.x and so on.