we use the wrapper for sql queries instead of the raw ones.

I have a collection, which has two fields A and B. 
I want to query when (A = red AND B = square) OR (A = blue AND  = circle)

When we try to use addAttributeToFilter, I don't see any option to handle such cases.

So, is there any way I can fetch data in a case like this?


Something like this should work.

        new \Zend_Db_Expr("(A = 'red' AND B = 'square') OR (A = 'blue' AND B = 'circle')")
  • Will this work : Mage::getModel('sales/order') ->getCollection()->getSelect() ->where( new \Zend_Db_Expr("(state = 'complete') OR (state = 'canceled')") ); – arqam Mar 25 '20 at 21:06

Or condition should work like this

// Or
        'attribute' => 'status',
        'eq'      => 'complete',
        'attribute' => 'status',
        'eq'        => 'canceled',

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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