yiiext / activerecord-relation-behavior

Inspired by and put together the awesomeness of many yii extensions that aim to improve saving of related records. Comes with 100% test coverage and well structured and clean code so it can savely be used in enterprise production enviroment.
http://www.yiiframework.com/extension/activerecord-relation-behavior/
Other
92 stars 28 forks source link

relations defined with 'through' are not supported yet #14

Open cebe opened 12 years ago

cebe commented 12 years ago

try adding support for it:

http://www.yiiframework.com/doc/guide/1.1/en/database.arr#relational-query-with-through

tom-- commented 11 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.

samdark commented 11 years ago

Yes, it is.

luxcem commented 10 years ago

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 ?

motin commented 9 years ago

Any news on this? @arnaud-f Did you finish your development and have anything to share?

motin commented 9 years ago

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