关联:
'users' => array(self::MANY_MANY, 'Users', 'comments_views(comment_id, user_id)', 'together' => true),
SQL:
LEFT OUTER JOIN "comments_views" "users_users"
ON (
"t"."id"="users_users"."comment_id"
)
LEFT OUTER JOIN "users" "users"
ON (
"users"."id"="users_users"."user_id"
)
如何修改关系以获取此sql:
LEFT OUTER JOIN "comments_views" "users_users"
ON (
"t"."id"="users_users"."comment_id"
AND "users_users"."user_id" = <param>
)
LEFT OUTER JOIN "users" "users"
ON (
"users"."id"="users_users"."user_id"
)
答案 0 :(得分:1)
您应该使用on
而不是condition
。
'users' => array(
self::MANY_MANY,
'Users',
'comments_views(comment_id, user_id)',
'together' => true
),
成为
'users' => array(
self::MANY_MANY,
'Users',
'comments_views(comment_id, user_id)',
'together' => true,
'on'=>'users_users.user_id=:user_id',
'params'=>array(':user_id' => $user_id),
),
理想情况下,users_users
应替换为关系名称。