我正在努力找到一个好的解决方案,使用set::extract()
或其他东西。我想在可包含的内容中添加GROUP BY:
$params = array(
'conditions'=>array(
'Project.id'=>$ProjectId
),
'contain'=>array(
//Gets the User Who owns the Project
'User'=>$user,
'Bid'=>array(
//The User Who owns the Bid
'User'=>$user
),
'ProjectType',
'Os',
'Comment'=>array(
'To'=>$user,
'From'=>$user,
'group'=>"Comment.from_id"
),
),
);
//debug($params);
return $this->find('first',$params);
我不想破解这个问题 - 有更简单的方法吗?
对于其他任何通过谷歌发现这一点的人来说,看起来GROUP BY
条件是可包含的查询aren't supported in Cake 1 or 2,因此如果必须进行分组,则需要手动加入。
您可以在包含的项目中执行条件:
'contain'=>array(
'Comment'=>array(
'To'=>$user,
'From'=>$user,
'conditions'=>array(
'group'=>"Comment.from_id"
),
),
)