3

我要疯了,试图找到一个好的解决方案,要么使用 theset::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);

我不想破解这个问题 - 有没有更简单的方法可以做到这一点?

4

2 回答 2

5

对于通过 Google 偶然发现此问题的任何其他人,Cake 1 或 2 似乎不支持可GROUP BY包含查询的条件,因此如果必须进行分组,则需要手动连接。

于 2014-02-07T17:18:25.783 回答
-1

您可以在包含的项目中执行条件:

'contain'=>array(
    'Comment'=>array(
        'To'=>$user,
        'From'=>$user,
        'conditions'=>array(
            'group'=>"Comment.from_id"
        ),
     ),
)

http://book.cakephp.org/view/1323/Containable

于 2011-11-02T10:10:41.027 回答