Download the PHP package alexinator1/yii2-jta without Composer
On this page you can find all versions of the php package alexinator1/yii2-jta. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alexinator1/yii2-jta
More information about alexinator1/yii2-jta
Files in alexinator1/yii2-jta
Package yii2-jta
Short Description Yii2 extension allows to access attributes of junction table and attach them as child model as properties in many-to-many relation
License MIT
Informations about the package yii2-jta
Yii2 Junction Table Attributes
================= A simple extension allows to access column values of junction table in ORM way without declaring additional model for that table in many-to-many relation. Extension overwrites \yii\db\ActiveQuery::viaTable() and allows to pass there array of column names of junction table which will be attached to child models as properties.
Requirements
- Yii 2.0
- PHP 5.4
Installation
The preferred way to install this extension is through Composer.
Either run
or add
to the require
section of your composer.json
file.
Usage
Just inherit your both model classes related in many-to-many relation from alexinator1\jta\ActiveRecord class.
Consider following scheme
and pass array of attribute names you want to attach to child model to viaTable method
That's it. Now child model has a property which named as pivot attribute and contains array of corresponding values indexed by parent id. So it can't be accessed following way:
Lazy loading:
Eager loading:
Eager loading using 'joinWith' methods:
works with 'array' models as well:
Show case page!
You may find more code samples in DEMO page. And some unit tests on DEMO page repository
Note!
Failed use cases
If you find any usecases where extension doesn't work properly. Please feel free to issue it or send me to email. We will try to handle it ASAP.
License
yii2 junction table attributes is released under the MIT License. See the bundled LICENSE.md
for details.