0

Is it possible to get the SQL condition like this:

WHERE ( (field_1 = 'a' AND field_2 = 'b') OR (field_1 = 'c' AND field_2 = 'd') OR ... ) ?

using addFieldToFilter() method?

I know about getSelect() method. The question about addFieldToFilter method only.

1 Answer 1

0

Hey In my knowledge we can do it not same as you mentioned in your question but yes likely we can do it as:

$collection->addAttributeToFilter(
    array(
        array('attribute'=> 'someattribute','like' => 'value'),
        array('attribute'=> 'otherattribute','like' => 'value'),
        array('attribute'=> 'anotherattribute','like' => 'value'),
    )
); 

here in array we need to specify the attribute and value and it will give you output as in where clause like:

WHERE ((someattribute LIKE 'value') OR (otherattribute LIKE 'value') OR (anotherattribute LIKE 'value'))

For more information you can look into this answer too.Hope this help.

1
  • Thanks, but I asked about addFieldToFilter method, not addAttributeToFilter. I use a simple (not-EAV) collection.
    – sergei.sss
    Nov 13, 2018 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.