Open cebe opened 12 years ago
i don't use MANY_MANY
, i only use 'through'
. if i understand the discussions on yii2 design on the forum, MANY_MANY
is on the way out.
Yes, it is.
I'm developing the support for 'through' relations but I wonder how to pass the data to the behaviour.
eg considering the scheme at http://www.yiiframework.com/doc/guide/1.1/en/database.arr#relational-query-with-through and the scenario in which a group is saved with its users and their roles.
class Group extends CActiveRecord
{
...
public function relations()
{
return array(
'roles'=>array(self::HAS_MANY,'Role','group_id'),
'users'=>array(
self::HAS_MANY,'User',array('user_id'=>'id'),'through'=>'roles'
),
...
);
}
}
When Group is saved should it have data in $group->roles
or in $group->users
eg :
$this->roles=array(
array('user_id' => $user_id1, 'name' => $name1),
array('user_id' => $user_id2, 'name' => $name2),
...
);
// versus :
$this->users=array(
array('user_id' => $user_id1, 'name' => $name1),
array('user_id' => $user_id1, 'name' => $name1),
...
);
I think that the second option make more sense : in many situations "roles" is just a association table with additional fields. What we really want to save is the "users" array.
What do you think ? Maybe you have other ideas ?
Any news on this? @arnaud-f Did you finish your development and have anything to share?
Here is some basic logic for saving has many relations with through vs without: https://github.com/neam/yii-relations-ui-core/blob/8ae18ab86f44d5a267d67b1ce4b260386466e8bb/behaviors/HasManyHandsontableInputBehavior.php#L159-L165
try adding support for it:
http://www.yiiframework.com/doc/guide/1.1/en/database.arr#relational-query-with-through