【问题标题】:Apply where condition on 2nd level association in CakePHP 2.5.x在 CakePHP 2.5.x 中对二级关联应用 where 条件
【发布时间】:2016-09-05 14:22:31
【问题描述】:

我想在 cakephp 中为我的 2 级关联添加 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);

【问题讨论】:

    标签: cakephp model-associations cakephp-2.5


    【解决方案1】:
    $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

    【讨论】:

    • 它正在工作,但它给了我左连接的结果,就像它给了我用户不匹配的用户 null 的结果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-12
    • 1970-01-01
    • 2013-09-28
    • 2015-06-28
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    相关资源
    最近更新 更多