Cakephp 3查询或条件

use*_*656 5 cakephp-3.0

伙计们,我如何在以下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']]);
}
Run Code Online (Sandbox Code Playgroud)

成为类似的东西

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

ari*_*lia 8

return $q->where(['OR' => [
    'IbCommisions.ib_id' => $this->userid,
    'Users.country_id' => $this->request->data['country']
]]);
Run Code Online (Sandbox Code Playgroud)

或者

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

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

  • 为了将来参考,不推荐使用文档中的“orWhere”。`从 3.5.0 开始,不推荐使用 orWhere() 方法。此方法根据当前查询状态创建难以预测的 SQL。使用 where() 代替,因为它具有更可预测且更易于理解的行为。` (2认同)