0

关系:

'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"
)
4

1 回答 1

1

你应该使用onnot 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应替换为关系的名称。

于 2013-01-30T15:06:22.823 回答