문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top