Palanikumar
Palanikumar

Reputation: 1746

Magento collection filter

In magento collection I want to filter values using "store" attribute. I have some values in array. Based on that array I need to filter values. But both below functions are not working.

$collection->addAttributeToFilter('store',array('in' => array(1,2,3)));
$collection->addFilter('store',array('in' => array(1,2,3));

Is there any other possibility to make it work?

Upvotes: 2

Views: 19098

Answers (2)

bahadirdogru
bahadirdogru

Reputation: 71

This is because the calculated sql will be like this:

select 'fields' from 'tablename' where stores in ('1','2','3');

As you can see in operator needs an array.

Upvotes: 0

Palanikumar
Palanikumar

Reputation: 1746

$collection->addFieldToFilter('stores', array('in' => array(1,2,3)));

addFieldToFilter did the job :)

Upvotes: 4

Related Questions