CakePHP 2.x GROUP BY within Containable

Deadly 提交于 2019-12-07 14:58:59

问题


I am going nuts trying to find a good solution, either using the set::extract() or something. I want to add a GROUP BY within my containable:

$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);

I do not want to hack to get around this issue - is there an easier way to do this?


回答1:


For anyone else that stumbles on this via Google, it looks as though GROUP BY conditions for containable queries aren't supported in Cake 1 or 2, so a manual join would be required if grouping is a must.




回答2:


You can do conditions within contained items:

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

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



来源:https://stackoverflow.com/questions/7970873/cakephp-2-x-group-by-within-containable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!