2017 © Pedro Peláez
 

yii2-extension yii2-many-to-many

Extension many to many relation for Yii2 Framework.

image

evgeny-gavrilov/yii2-many-to-many

Extension many to many relation for Yii2 Framework.

  • Wednesday, November 25, 2015
  • by EvgenyGavrilov
  • Repository
  • 3 Watchers
  • 2 Stars
  • 441 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 3 % Grown

The README.md

Yii2 many to many behavior

Build Status Packagist Code Climate Test Coverage, (*1)

This behavior allows to update or delete relations in the junction table, which are described in the model with via() or viaTable()., (*2)

Behavior doesn't use transaction. Use this method to do transactions() in the model or other way., (*3)

Install

php composer.phar require evgeny-gavrilov/yii2-many-to-many

Usage

Connection of behavior and description of the relation in the model

class User extends ActiveRecord
{
    public function behaviors()
    {
        return [
            EvgenyGavrilov\behavior\ManyToManyBehavior::className()
        ];
    }

    public function getGroups()
    {
        return $this->hasMany(Group::className(), ['id' => 'group_id'])->viaTable('user_group', ['user_id' => 'id']);
    }
}

Usage in the code

$user = User::findOne(1);
// Add new or update relation
$model->setRelated('groups', [1]);
// or
$model->setRelated('groups', [1, 2]);
$model->save();

// Add or update the data with the remove old relations
$model->setRelated('groups', [1, 2], true);
$model->save();

// Delete all relations
$model->setRelated('groups', [], true);
$model->save();

The Versions

25/11 2015

dev-master

9999999-dev

Extension many to many relation for Yii2 Framework.

  Sources   Download

MTI

The Requires

 

by Evgeny Gavrilov

yii2 behavior relation many to many

25/11 2015

v1.1.0

1.1.0.0

Extension many to many relation for Yii2 Framework.

  Sources   Download

MTI

The Requires

 

by Evgeny Gavrilov

yii2 behavior relation many to many

18/04 2015

v1.0.0

1.0.0.0

Extension many to many relation for Yii2 Framework.

  Sources   Download

MTI

The Requires

 

by Evgeny Gavrilov

yii2 behavior relation many to many