Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
筛选时,magento网格找不到该列_Magento_Magento 1.4 - Fatal编程技术网

筛选时,magento网格找不到该列

筛选时,magento网格找不到该列,magento,magento-1.4,Magento,Magento 1.4,我有一个自定义模块,它有自己的网格。我拉入网格的一个字段是与条目关联的记录和注释的计数。它工作正常,在网格中显示计数,排序也很好,但是当我过滤时,我收到一条消息,说它找不到列 以下是错误: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'note_count' in 'where clause' 这是代码 class Ssi_Crm_Model_Mysql4_Quote_Collection extends Mage_Core_M

我有一个自定义模块,它有自己的网格。我拉入网格的一个字段是与条目关联的记录和注释的计数。它工作正常,在网格中显示计数,排序也很好,但是当我过滤时,我收到一条消息,说它找不到列

以下是错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'note_count' in 'where clause'
这是代码

class Ssi_Crm_Model_Mysql4_Quote_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{

    protected function _construct()
    {
        $this->_init('crm/quote');
    }

    protected function _initSelect()
    {
        parent::_initSelect();
        $this->_joinUserSet();
        return $this;
    }

    protected function _joinUserSet()
    {
        $this->getSelect()
         ->columns("(SELECT COUNT(note) FROM mage_crm_notes WHERE entity_id = main_table.quote_id AND entity_type = 'quote') as note_count")
            ->join(
                array('user'=>$this->getTable('admin/user')),
                'main_table.user_id=user.user_id',
                array('username' => 'user.username', 'email' => 'user.email'));


        return $this;

    }

Chris,您不能在mySql Where子句中使用别名,这就是您在尝试筛选结果时出错的原因。这不是mySql错误,但请参见

假设您的sql是

选择字段1、字段2,从mage_crm_notes中选择COUNTnote,其中entity_id=main_table.quote_id和entity_type='quote'作为mage_crm中的note_count

你会得到你期望的三列

:field1:field2:注意\u计数:

但是你不能有

选择字段1、字段2,从mage_crm_notes中选择COUNTnote,其中实体_id=main_table.quote_id和实体_type='quote'作为mage_crm中的note_count>5的note_count

因为您将在where子句错误中获得未知列“note\u count”


根据过滤方式的不同,可以使用HAVING子句。通过StackOverflow搜索类似的查询,例如。

处理此问题的一种方法是使用集合,而不是查询,以便它知道如何正确过滤

请尝试,而不是getSelect->columns

如果不使用EAV集合,则实现与addExpressionAttributeToSelect相同效果的不美观方法是:


你能提供mage_crm_notes的结构吗?此外,在列行中,您似乎正在与另一个表连接,但不清楚是哪一个:您能解释查询吗?是的,很好,唯一的问题是magento基代码使用where呈现过滤器,我不打算进行重写。我正在调用underfined方法。我所处的函数覆盖了Mage_Core_Model_Mysql4_Collection_AbstractPoint,我没有注意到您使用的是扁平化的集合。
$this->addExpressionAttributeToSelect('note_count',
    '(SELECT COUNT(note) FROM mage_crm_notes WHERE entity_id = main_table.quote_id AND entity_type = "quote")',
    ''
)
->joinTable(
    array('user'=>'admin/user'),
    'user_id=user_id',
    array('username' => 'user.username', 'email' => 'user.email')
);
$this->_map['fields']['note_count'] = '(SELECT COUNT(note) FROM mage_crm_notes WHERE entity_id = main_table.quote_id AND entity_type = "quote")';