suver/yii2-behavior-subset

Behavior Subset

Installs: 54

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Language:HTML

Type:yii2-extension

1.1.2 2019-04-29 13:27 UTC

This package is not auto-updated.

Last update: 2024-11-24 03:14:24 UTC


README

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