题
为什么我不能做以下操作:
$this->getSelect()
->columns(
array(
'ordered_qty' => 'COUNT(DISTINCT main_table.entity_id)',
'invoiced_qty' => new Zend_Db_Expr('( select COUNT(OI.item_id) AS Ct from sales_flat_order_item AS OI WHERE OI.order_id=main_table.entity_id ) AS invoiced_qty')
)
);
子查询因错误而失败,“无法确定字段名称”
解决方案
您的问题没有足够的上下文来提供具体的答案,因此我要解释为什么Magento抛出了一条消息
无法确定字段名称
希望这将为您提供足够的信息来跟踪问题。
在股票洋红色系统中, 只要 将错误“无法确定字段名称”出现为
#File: app/code/core/Mage/Sales/Model/Resource/Collection/Abstract.php
protected function _attributeToField($attribute)
{
$field = false;
if (is_string($attribute)) {
$field = $attribute;
} elseif ($attribute instanceof Mage_Eav_Model_Entity_Attribute) {
$field = $attribute->getAttributeCode();
}
if (!$field) {
Mage::throwException(Mage::helper('sales')->__('Cannot determine the field name.'));
}
return $field;
}
所以,如果 _attributeToField
方法传递了一个属性值
一个空字符串
一个属性对象
getAttributeCode
返回false(或众多值之一,PHP考虑false-ish)不是
Mage_Eav_Model_Entity_Attribute
或字符串
然后,“无法确定字段名称”被抛出。
在标准系统中,当您调用收集对象时,Magento调用此方法 addAttributeToSelect
, addAttributeToFilter
, addAttributeToSort
, , 或者 addAttributeToSearchFilter
方法。
因此,关于您的代码的某些内容导致无效的值传递给 _attributeToField
. 。这意味着问题不是您的子问题,或者子查询可能会改变导致无效值传递的事物。