suver/yii2-behavior-subset Behavior Subset

extensionbehaviorfarpsesubset

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

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



1.1.2 is the latest of 5 releases



Apache-2.0 license
Stats
0 github stars & 0 github forks
0 downloads in the last day
0 downloads in the last 30 days
54 total downloads