0

I added this condition to my collection for adding the or condition:

$collection->addFieldToFilter(
array('city','mobile_badge'),
 array(array('eq' => $arealist),
'1'));

But it returns the wrong result. This $collection->getAllIds(); also returns the correct ids. But when I execute

$collection->getSelect();

it's gives me correct values.

2 Answers 2

0

Check your syntax for addFieldToFilter with multiple fields.

Your function should be like below:

$collection->addFieldToFilter(
    array('city', 'mobile_badge'),
    array(
        array('eq' => $arealist), 
        array('eq' => '1')
    )
)

Please refer this for better understanding.

5
  • Call to undefined method ::getAllIdsSql() Commented Jan 6, 2016 at 6:52
  • Which collection are you using, custom module collection ?
    – Vicky Dev
    Commented Jan 6, 2016 at 6:59
  • yes this is custom module collection.. Commented Jan 6, 2016 at 7:00
  • Updated my answer, please check.
    – Vicky Dev
    Commented Jan 6, 2016 at 7:12
  • no change still the same result.. Commented Jan 6, 2016 at 7:13
0

Try this

$collection = Mage::getModel('{your_module_name}/{your_model_name}')->getCollection();
        $collection->addFieldToFilter(
            array('city','mobile_badge'),
            array(
                array('eq' => $arealist),
                array('eq' => 1)
            ));
        print_r($collection->getAllIds());

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.