2
votes

How to Add/Delete new MANY_MANY relation in Yii? For Example i have a many-to many relation with users and projects. And the relations are set in the table 'project_user_assignment'. I needed to add/Edit/Remove the relations from the table 'project_user_assignment'.

User Model

 public function relations()
  {
    return array('projects' => array(self::MANY_MANY, 'Project', 'project_user_assignment(user_id, project_id)'),
        );
 }

Project Model

 public function relations()
{
    return array(
        'users' => array(self::MANY_MANY, 'User', 'project_user_assignment(project_id, user_id)'),
    );
}
1

1 Answers

1
votes

Create a Model for project_user_assignment table that way you can use the model to add/delete/edit the records