无法确定 magento 过滤器查询中的字段名称
我在 Magento 查询中使用 OR 过滤器时遇到问题。这就是我使用的:
$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 ANDcreated_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。
I'm having trouble with using an OR filter in a Magento query. This is what i used:
$collection = Mage::getModel('sales/order')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter(
array(
array('attribute'=>'status','eq'=>'pending'),
array('attribute'=>'created_at', 'from'=>$startDate, 'to'=>$finishDate)
)
);
I want the following WHERE statement: WHERE 'status' = 'pending' OR (created_at < $startDate AND created_at > $finishDate)
but i get the following error message
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
I am currently using version 1.6-2rc.
据我所知,您不能使用
addAttributeToFilter()
来OR
销售/订单 模型的两个属性。使用
addAttributeToSearchFilter()
代替:这将创建一个 WHERE 子句:
Afaik you cannot use
addAttributeToFilter()
toOR
two attributes for thesales/order
model.Use
addAttributeToSearchFilter()
instead:This will create a WHERE clause of: