Model behavior for relation data management
To install with composer:
$ php composer.phar require diiimonn/yii2-behavior-relation-follow "dev-master"
or add
"diiimonn/yii2-behavior-relation-follow": "dev-master"
to the require
section of your composer.json
file.
...
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