Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cakephp 3 query OR Condition

Tags:

cakephp-3.0

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']])
like image 421
user1292656 Avatar asked Jul 28 '16 12:07

user1292656


1 Answers

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

like image 116
arilia Avatar answered Nov 13 '22 00:11

arilia