Model related with itself

I have declared the following to relations:

'following' => array(self::MANY_MANY, 'User', 'connections(userId,relatedUserId)',

    'condition' => '`following`.`deleted` = 0',

    'index' => 'id',


'followers' => array(self::MANY_MANY, 'User', 'connections(relatedUserId,userId)',

    'condition' => '`followers`.`deleted` = 0',

    'index' => 'id',


It works fine, but I would like a relation which returns the same result as:

return $user->following + $user->followers;

Any ideas? Thanks.

  • in "$user->following + $user->followers" means union or intersection (and condition)?

if you are trying union, try this -

‘on’=>’following.deleted = 0 or followers.deleted = 0’

i have used ‘on’ instead of ‘condition’… check this out for the reason