evgeny-gavrilov/yii2-many-to-many 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

evgeny-gavrilov/yii2-many-to-many

最新稳定版本:v1.1.0

Composer 安装命令:

composer require evgeny-gavrilov/yii2-many-to-many

包简介

Extension many to many relation for Yii2 Framework.

README 文档

README

Build Status Packagist Code Climate Test Coverage

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

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

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();

统计信息

  • 总下载量: 1.59k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MTI
  • 更新时间: 2015-03-30