0

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?

1

Something like this should work.

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

Or condition should work like this

// Or
$collection->addAttributeToFilter(array(
    array(
        'attribute' => 'status',
        'eq'      => 'complete',
    ),
    array(
        'attribute' => 'status',
        'eq'        => 'canceled',
    ),
));
|improve this answer|||||

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.