CakePHP 2.x GROUP BY在Containable内

问题描述 投票:3回答:2

我正在努力找到一个好的解决方案,使用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);

我不想破解这个问题 - 有更简单的方法吗?

php cakephp lamp cakephp-2.x
2个回答
5
投票

对于其他任何通过谷歌发现这一点的人来说,看起来GROUP BY条件是可包含的查询aren't supported in Cake 1 or 2,因此如果必须进行分组,则需要手动加入。


-1
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.