I am developing REST API in Yii2. In search query i want to achieve this
WHERE ((`variant_name` LIKE '%size%' AND `variant_value`
LIKE '%12%') OR (`variant_name` LIKE '%color%' AND `variant_value` LIKE '%12%'))
the variant_name and variant_value are an array sent in the URL. The corrsponding Yii2 code i am using right now is as follows
$query->andFilterWhere(['or',
['or like', 'pvo.variant_name', $this->variant_name],
['or like', 'pvo.variant_value', $this->variant_value]])
->groupBy(['pvo.product_variant_id'])
->having(['count(product_variant_id)' => count($this->variant_name)]);
;
Which is generating the following SQL
AND ((`variant_name` LIKE '%size%' OR .`variant_name` LIKE '%color%')
OR (`variant_value` LIKE '%13%' OR `variant_value` LIKE '%56%')))
But i want varaint_name[0] and varaint_value[0] in single bracket having AND condition with varaint_name[1] and varaint_value[1] like mentioned above. Kindly guide me how should i go about it in Yii2?
Update 1 Sample URL http://localhost:8080/online-malls/api/web/v1/products?expand=product_variant_options&variant_name[0]=size&variant_value[0]=13&variant_name[1]=color&variant_value[1]=56