diiimonn/yii2-behavior-relation-follow

There is no license information available for the latest version (v1.0.0) of this package.

v1.0.0 2015-02-23 12:23 UTC

This package is not auto-updated.

Last update: 2024-04-27 14:17:30 UTC


README

Model behavior for relation data management

Installation

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.

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']);
}
...

in my-view/_form.php

Select multiple from relation model. Recommended use yii2-widget-checkbox-multiple