【问题标题】:Cakephp 3 query OR ConditionCakephp 3 查询或条件
【发布时间】:2016-07-28 12:02:39
【问题描述】:

伙计们,我如何在以下 Where 语句中应用 OR 条件?

$this->IbCommisions->find()->matching(
    'Users.Accounts',function ($q) {
        return $q->where(['IbCommisions.ib_id' => $this->userid, 'Users.country_id' => $this->request->data['country']]);
}

变成这样的人

(['IbCommisions.ib_id' => $this->userid OR 'Users.country_id' => $this->request->data['country']])

【问题讨论】:

    标签: cakephp-3.0


    【解决方案1】:
    return $q->where(['OR' => [
        'IbCommisions.ib_id' => $this->userid,
        'Users.country_id' => $this->request->data['country']
    ]]);
    

    或者

    return $q->where(['IbCommisions.ib_id' => $this->userid])
        ->orWhere(['Users.country_id' => $this->request->data['country']]);
    

    http://book.cakephp.org/3.0/en/orm/query-builder.html#advanced-conditions

    【讨论】:

    • 为了将来参考,文档中的 orWhere 已弃用。 As of 3.5.0 the orWhere() method is deprecated.This method creates hard to predict SQL based on the current query state. Use where() instead as it has more predictable and easier to understand behavior.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-03
    相关资源
    最近更新 更多