YII » On Many Many Relationships
Published on 12/3/2010
- If you have a composite primary key, make sure you override the primaryKey method in your model, like this:
public function primaryKey()
{
return array('field_one', 'field_two');
}
- Now, you cannot generate Gii CRUD operations when you have a composite primary key, but you can make a model and a controller and forms, so you can just do some of it manually.
You can do something like this in your controller, with a (blog) Posting table with many-many related tags:
public function actionDelete($id)
{
$posting_id=$_GET['posting_id'];
$pk = array('posting_id'=>$posting_id, 'tag_id'=>$id);
PostingTag::model()->deleteByPk($pk);
}
... views