我的UserBan模型中定义了以下关系:
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'),
);
}
现在,当我尝试这样做时:
$criteria->with = array('user', 'target');
它尖叫如下,因为 User mdel 与 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))
我该如何克服呢?我在哪里“别名”我的连接表?
编辑这是用户模型的默认范围:
public function defaultScope()
{
return array(
'with' => 'nicknames',
'together' => true
);
}