在CakePHP 2.5.x中的第二级关联中应用where条件

时间:2016-09-05 14:22:32

标签: cakephp model-associations cakephp-2.5

我想在cakephp中为我的第二级关联添加一个where子句。根据我的理解,这应该有效,但它给了我一个错误

错误:[PDOException] SQLSTATE [42S22]:找不到列:1054'where子句'中的未知列'User.email_address'。

$options = array(
    'contain' => array(
        'People',
        'People' => array('User')
    ),
    'conditions'=> array(
        'User.email_address' => 'sample@mail.com'
    ), 
    'recursive' =>1,
);
$query = $this->Organization->find('all', $options);

1 个答案:

答案 0 :(得分:2)

$options = array(
    'contain' => array(
        'People' => array(
            'User' => array(
                'conditions'=> array(
                    'User.email_address' => 'sample@mail.com'
                ),
            ),
        ),
    ),
    //'recursive' =>1,
);
$query = $this->Organization->find('all', $options);

了解更多:

<强> http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html#containing-deeper-associations