cakephp paginate与相关模型

时间:2014-07-01 15:49:27

标签: cakephp pagination

用户有很多User_Questionaries。我想要具有特定问卷的分页用户。我使用了以下分页。

$paginate = array(
    'conditions' => array(
        'User.role' => IWOA,
        'UserQuestionary.questionary_id' => $id
    ),
    'recursive' => 1,
    'limit' => 10,
    'order' => array(
        'name' => 'asc'
    ),
    'contain' => array('UserQuestionary')
);

但它不是创建连接查询。它显示Unknown column UserQuestionary.questionary_id' in 'where clause'

问题是什么?我该怎么做?

1 个答案:

答案 0 :(得分:0)

最后,我使用了连接查询来执行此操作。

$paginate = array(
            'conditions' => array(
                'Iwoa.role' => IWOA,                
            ),
            'joins' => array(
                array(
                    'alias' => 'UserQuestionary',
                    'table' => 'user_questionaries',
                    'type' => 'LEFT',
                    'conditions' => 'UserQuestionary.user_id = Iwoa.id AND UserQuestionary.questionary_id = ' . $id
                )
            ),
            'limit' => 10,
            'order' => array(
                'name' => 'asc'
            ),
        );