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?

2 Answers 2

1

Something like this should work.

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

Or condition should work like this

// Or
$collection->addAttributeToFilter(array(
    array(
        'attribute' => 'status',
        'eq'      => 'complete',
    ),
    array(
        'attribute' => 'status',
        'eq'        => 'canceled',
    ),
));
0

Your Answer

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

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