Download the PHP package antonyz89/yii2-many-to-many without Composer
On this page you can find all versions of the php package antonyz89/yii2-many-to-many. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download antonyz89/yii2-many-to-many
More information about antonyz89/yii2-many-to-many
Files in antonyz89/yii2-many-to-many
Package yii2-many-to-many
Short Description Many-to-many ActiveRecord relation for Yii 2 framework. Created By Alexey Rogachev, forked by AntonyZ89
License BSD-3-Clause
Homepage https://github.com/arogachev/yii2-many-to-many
Informations about the package yii2-many-to-many
Yii 2 Many-to-many
Implementation of Many-to-many relationship for Yii 2 framework.
Created by arogachev, forked by AntonyZ89
- Yii 2 Many-to-many
- Installation
- Features
- Creating editable attribute
- Attaching and configuring behavior
- Attribute validation
- Adding control to view
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json
file.
Features
- Configuring using existing relations
- Multiple relations
- No extra queries. For example, if initially model has 100 related records, after adding just one, exactly one row will be inserted. If nothing was changed, no queries will be executed.
- Auto filling of editable attribute
- Validator for checking if the received list is valid
Creating editable attribute
Simply add public property to your ActiveRecord
model like this:
It will store primary keys of related records during update.
Attaching and configuring behavior
First way is to explicitly specify all parameters:
Attribute validation
Add editable attribute to model rules for massive assignment.
Or use custom validator:
Validator checks list for being array and containing only primary keys presented in related model.
It can not be used without attaching ManyToManyBehavior
.
Adding control to view
Add control to view for managing related list. Without extensions it can be done with multiple select:
Example of getList()
method contents (it needs to be placed in User
model):
Global Auto Fill
By default, all ManyToMany relations are auto filled after trigger ActiveRecord::EVENT_AFTER_FIND
event, but if you want disable this feature and fill relations manually:
And set autoFill
as true
on behaviors when you want enable auto fill on specific model
If $enableAutoFill
and autoFill
are false
, you should call $model->fill()
to fill relations manually