Latheesan
Latheesan

Reputation: 24116

Magento addFieldToFilter on collection - how do to get a AND where clause

I have the following code to load a custom collection:

echo Mage::getModel("ibi/despatchqueues")
->getCollection()
->addFieldToFilter(
    array(
        'can_sync',
        'is_synced'
    ),
    array(
        array('eq' => 1), // can_sync  = 1
        array('eq' => 0), // is_synced = 0
    )
)
->getSelect();

This produces the following SQL Query:

SELECT `main_table`.* FROM `despatchqueues` AS `main_table` 
WHERE (((can_sync = 1) or (is_synced = 0)))

How do I change my addFieldToFilter so that the resulting query will look like this:

SELECT `main_table`.* FROM `despatchqueues` AS `main_table` 
WHERE (((can_sync = 1) and (is_synced = 0)))

Upvotes: 1

Views: 2201

Answers (1)

Lalit Kaushik
Lalit Kaushik

Reputation: 1062

try like this

 echo Mage::getModel("ibi/despatchqueues")
->getCollection()
->addFieldToFilter('can_sync', array('eq' => 1))
->addFieldToFilter('is_synced', array('eq' => 0))
->getSelect();

Hope this helps!

Upvotes: 4

Related Questions