关于集合的Magento addFieldToFilter - 如何获取AND where子句

时间:2014-05-07 10:55:34

标签: sql magento

我有以下代码来加载自定义集合:

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();

这会产生以下SQL查询:

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

如何更改addFieldToFilter,以便生成的查询如下所示:

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

1 个答案:

答案 0 :(得分:4)

试试这个

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

希望这有帮助!