user1292656
user1292656

Reputation: 2560

Cakephp 3 query OR Condition

Guys how can I apply an OR condition in the following Where statement ?

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

To become something like

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

Upvotes: 8

Views: 22035

Answers (1)

arilia
arilia

Reputation: 9398

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

or alternatively

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

Upvotes: 18

Related Questions