0

Need to generate the following query with getCollection() however unable to figure it out.

(id_path = '12/xyz') OR (request_path = '/abc' AND store_id = '1')

Tried the following but I need it the other way:

//gives (...) AND (.. OR ..)

$collection->addFieldToFilter('id_path', '12/xyz');
$collection->addFieldToFilter(
    array('store_id', 'request_path'), 
    array('1', '/abc')
 );
1

1 Answer 1

2

Try this collection

$subSelect = clone $collection;
$subSelect->addFieldToFilter('request_path', '/abc')->addFieldToFilter('store_id', 1);
$collection->addFieldToFilter(
    array('id_path', 'entity_id'),
    array(
        array('eq' => '12/xyz'),
        array('in' => $subSelect->getAllIds()),
    )
);

var_dump($collection->getSelect()->__toString());
2
  • Hey, thanks - that looks like a way to do it without having to write raw where SQL.
    – Tom
    Dec 25, 2018 at 8:33
  • Well it was just for debugging, the var_dump line Dec 25, 2018 at 8:34

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