2

How to get magento collection by next condition:

where (url_from = "1" AND url_to = "2") 
OR    (url_from = "2" AND url_to = "1")

Thank you!

1
  • 2
    it's hard to understadn from you given code so i guess you want something like that $_products->addFieldToFilter('url_from', array('in' => array(1,2))); $_products->addFieldToFilter('url_to', array('in' => array(2,1))); Commented Apr 27, 2016 at 9:35

1 Answer 1

1

you want something like that

$_products->addFieldToFilter('url_from', array('in' => array(1,2))); 
$_products->addFieldToFilter('url_to', array('in' => array(2,1)));
7
  • That's the thing I need ) It will do the job. Thanks
    – esigns
    Commented Apr 27, 2016 at 10:03
  • @qaisar can you please help me in this question magento.stackexchange.com/questions/112860/…
    – Mujahidh
    Commented Apr 27, 2016 at 10:09
  • @fmrng still waiting for your answer Commented Apr 27, 2016 at 11:30
  • Trying to figure out, it's kinda complicated... while your solution is easy and would probably work fine in this case (it's unlikely I guess that to and from are equal), it is not logically correct, since it would be true even for combinations that shouldn't be true, like url_from=1 AND url_to=1.
    – fmrng
    Commented Apr 27, 2016 at 11:49
  • 1
    Sorry, but I realised after I posted that what it was doing was WHERE ((url_from = '1') OR (url_to = '2')) AND ((url_from = '2') OR (url_to = '1')), which is obviously not correct
    – fmrng
    Commented Apr 27, 2016 at 11:58

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