分组包含模型 [英] grouping contained models

查看:173
本文介绍了分组包含模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PresentationView hasMany SlideView

SlideView 模型具有字段持续时间。

SlideView model has field duration.

presentation_duration = SlideView.duration

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

我想为每个演示文稿使用presentation_duration获取演示文稿的列表(分页)。
到目前为止,我尝试这样:

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.

这两种方法都会出现一些SQL错误:

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?

推荐答案

不能将'group'传递给'contain'。要执行您希望执行的操作,您需要使用JOIN - 请参阅 CakePHP加入表

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.

这篇关于分组包含模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆