chinaka
(chinaka)
1
Below is what i want to achieve in plain SQL:
SELECT * from user WHERE status = self::STATUS_ACTIVE AND email = $email OR phone = $phone;
I tried the code below in active record and i keep getting unknown column:
return User::find()
->where([‘and’,[‘status’ => self::STATUS_ACTIVE],[‘or’,‘email’ => $email,‘phone’ => $phone]])
->one();
chinaka
(chinaka)
2
@softark please do you mind taking a look at this?
softark
(Softark)
3
Hi @chinaka,
You need to enclose the hash-format conditions in brackets.
return User::find()
->where([
‘and’,
[‘status’ => self::STATUS_ACTIVE],
// [‘or’, ‘email’ => $email, ‘phone’ => $phone]
[‘or’, [‘email’ => $email], [‘phone’ => $phone]]
])->one();
1 Like