yii2-behavior-relation-follow
Model behavior for relation data management, (*1)
Installation
To install with composer:, (*2)
$ php composer.phar require diiimonn/yii2-behavior-relation-follow "dev-master"
or add, (*3)
"diiimonn/yii2-behavior-relation-follow": "dev-master"
to the require
section of your composer.json
file., (*4)
Usage
in MyModel.php
...
use diiimonn\behaviors\RelationFollowBehavior;
...
public function behaviors()
{
return [
...
[
'class' => RelationFollowBehavior::className(),
'relations' => [
'books', // relation name
]
],
];
}
public function getBooks()
{
return $this->hasMany(BookModel::className(), ['id' => 'book_id'])->via('authorBooks');
}
public function getAuthorBooks()
{
return $this->hasMany(AuthorBooks::className(), ['author_id' => 'id']);
}
...
Select multiple from relation model. Recommended use yii2-widget-checkbox-multiple, (*5)