grouping contained models

为君一笑 提交于 2019-12-24 07:13:03

问题


PresentationView hasMany SlideView

SlideView model has field duration.

The presentation_duration = sum of all SlideView.duration fields from slide views that belong to the presentation.

I want to get list (paged) of presentations with presentation_duration for each presentation. So far I am trying like this:

$this->paginate['contain'] = array(
            'PresentationView' => array(
                'SlideView' => array(
                    'group' => 'SlideView.presentation_view_id',
                                    // 'conditions' => array('group' => 'SlideView.presentation_view_id'),
                )
            )
        ); 

The commented line is an option that I tried.

Both methods end up with some SQL errors:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'SlideView.group' in 'fieldlist'

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'group' in 'where clause'

It seems that contain doesn not even recognize group key - is it even possible to use grouping like this? If yes how I can do it?


回答1:


You cannot pass 'group' to your 'contain'. To do what you're hoping to do, you'll need to use JOINs - see CakePHP Joining Tables.



来源:https://stackoverflow.com/questions/15190385/grouping-contained-models

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