I have the following relations defined in my UserBan model:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'user' => array(self::BELONGS_TO, 'User', 'userId'),
'target' => array(self::BELONGS_TO, 'User', 'targetId'),
'author' => array(self::BELONGS_TO, 'User', 'authorId'),
);
}
Now when I try to do:
$criteria->with = array('user', 'target');
It screams the following because the User mdel has a default scoped relation to Nicknames:
Not unique table/alias: 'nicknames'
SQL:
SELECT COUNT(DISTINCT `t`.`id`) FROM `userban` `t`
LEFT OUTER JOIN `user` `user` ON (`t`.`userId`=`user`.`id`)
LEFT OUTER JOIN `nickname` `nicknames` ON (`nicknames`.`userId`=`user`.`id`)
LEFT OUTER JOIN `user` `target` ON (`t`.`targetId`=`target`.`id`)
LEFT OUTER JOIN `nickname` `nicknames` ON (`nicknames`.`userId`=`target`.`id`)
WHERE ((user.name LIKE :username) AND (:dateStart<=t.createdAt AND :dateEnd>=t.createdAt))
How do I get over this? Where do I "alias" my joined tables ?
EDIT Here is the default scope for the User model:
public function defaultScope()
{
return array(
'with' => 'nicknames',
'together' => true
);
}