1
我在使用Magento查询中的OR过滤器时遇到问题。这是我用什么:无法确定magento过滤器查询中的字段名称
$collection = Mage::getModel('sales/order')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter(
array(
array('attribute'=>'status','eq'=>'pending'),
array('attribute'=>'created_at', 'from'=>$startDate, 'to'=>$finishDate)
)
);
我想以下WHERE语句:WHERE 'status' = 'pending' OR (created_at < $startDate AND created_at > $finishDate)
但我得到以下错误消息
Fatal error: Uncaught exception 'Mage_Core_Exception' with message 'Cannot determine the field name.' in /home/content/r/o/n/ronakkaria/html/magento/app/Mage.php:563
Stack trace:
#0 /home/content/r/o/n/ronakkaria/html/magento/app/code/core/Mage/Sales/Model/Resource/Collection/Abstract.php(52): Mage::throwException('Cannot determin...')
#1 /home/content/r/o/n/ronakkaria/html/magento/app/code/core/Mage/Sales/Model/Resource/Collection/Abstract.php(80): Mage_Sales_Model_Resource_Collection_Abstract->_attributeToField(Array)
#2 /home/content/r/o/n/ronakkaria/html/new/admin/magentoInvoice/getInvocieList.php(43): Mage_Sales_Model_Resource_Collection_Abstract->addAttributeToFilter(Array)
#3 {main} thrown in /home/content/r/o/n/ronakkaria/html/magento/app/Mage.php on line 563
我目前使用的版本1.6-2rc。
顺便说一句,你提到你的问题的第一代码部分低于该条件是没有意义的(至少到我)。因为它意味着“包括在*'$ startDate'之前创建的订单和*在同一时间*'$ finishDate'之后创建的订单”,这很可能永远不会发生(除非您打算使用奇怪的值^^ )。我认为这只是一个错字,对吧? –
是的,只是一个错字,谢谢 – rosh3000