Skip to content

suver/yii2-behavior-subset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Frapse Behavior Subset

Behavior Subset

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require suver/yii2-behavior-subset

or add

"suver/yii2-behavior-subset": "*"

to the require section of your composer.json file.

Configure

Write you behaviors section like this for Many-To-Many

public function behaviors()
{
    return [
        [
            'class' => '\suver\behavior\Subset',
            'relation' => 'authors', // you relation
            'attribute' => 'authors_ids',
        ]
    ];
}

/**
 * Relation with Other Model
 *
 * @return \yii\db\ActiveQuery
 */
public function getAuthors()
{
    return $this->hasMany(OtherModel::className(), ['id' => 'other_model_id'])->viaTable('this_model_to_other_model', ['this_model_id' => 'id']);
}

Usage

Once the extension is installed, simply use it in your code by :

// save relation
$model->authors_ids = [1,2,3,4];
$model->save();

// get realtion
var_dump($model->authors)

yii2-behavior-subset

Behavior subset. Esey work with many to many relations