A
A
Artur Kosikov2017-09-30 10:10:28
Yii
Artur Kosikov, 2017-09-30 10:10:28

How to make such a Where in an SQL query on ActiveRecord?

Greetings!
There is a query to the database with the following condition:

...
WHERE ( `feature_id`, `value` ) IN (  ( 424, 'Бензин' ), ( 424, 'Гибрид' ), ( 424, 'Дизель' )  )
OR ( `feature_id`, `value` ) IN (  ( 425, 'Автоматическая' ), ( 425, 'Ручная' )  )
OR ( `feature_id`, `value` ) IN (   ( 426, 'Седан' ), ( 426, 'Фургон' ), ( 426, 'Универсал' )  )
...

How to do it on AR?
Of course, you can "stick" under the cycle through orWhere, but I want to beautifully combine, because there are many and different filters, i.e. I want ActiveRecord to send the request in this form...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem, 2017-09-30
@atillus

https://github.com/yiisoft/yii2/blob/master/docs/g...

Y
yiiworld, 2017-11-24
@yiiworld

$arQuery->AutoParams::find()
...
->where]]
-orWhere(['in', ['feature_id','value'], [ [425,'Автоматическая'], [425, 'Ручная']]])
-orWhere(['in', ['feature_id','value'], [ [426, 'Седан'], [426, 'Фургон'], [426, 'Универсал'] ]])
...
->all();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question