繁体   English   中英

Magento问题与外部mod“违反完整性约束:1052 where子句不明确的列'created_at'”

[英]Magento issue with external mod “Integrity constraint violation: 1052 Column 'created_at' in where clause is ambiguous”

$select->joinLeft(
       array('order_table' => $collection->getTable('sales/order')),
       'order_table.entity_id=main_table.entity_id',
       array('admin_user_id' => 'admin_user_id')
);

在导致错误的自定义magento模块中

Integrity constraint violation: 1052 Column 'created_at' in where clause is ambiguous

注释掉此代码可使magento正确运行,该代码位于观察器中

    public function salesOrderGridCollectionLoadBefore($observer)
    {
        $collection = $observer->getOrderGridCollection();
        $select = $collection->getSelect();
        $select->joinLeft(
           array('order_table' => $collection->getTable('sales/order')),
               'order_table.entity_id=main_table.entity_id',
            array('admin_user_id' => 'admin_user_id')
        );
    }

任何人都可以提出修复建议,这不是我的代码也不是我的模块,我不完全了解它所做的一切。

我猜想它在表中添加了一个字段并填充了它,然后允许您使用订单页面使用它进行搜索。

提前致谢。 -T

看一下'sfo_created_at' =>'sfo.created_at' ,它将重命名sales_flat_order.created_atsales_flat_order.sfo_created_at (您也可以从选择项中删除该字段)

$collection = $observer->getOrderGridCollection();
$collection->getSelect()->joinLeft(
    array('sfo' => 'sales_flat_order'),
    'main_table.entity_id=sfo.entity_id',
    array('sfo_created_at' =>'sfo.created_at', 'sfo.status')
);

我没有找到任何确切的结果来对此有所帮助的任何地方都在搜索过。 但是现在我知道发生这种情况的原因。它很简单,因为它说“违反完整性约束:1052列中where子句不明确的'created_at'”,意味着它正在查找另一个created_at字段。 因为当我们添加或联接另一个表时,它还有一个名为created_at的字段。 那么解决方案是什么?

任何想法……………

它很简单,只是告诉magento,created_at是main_table的而不是我的自定义表的,您怎么做,我将告诉您完整的过程。

步骤1.在销售订单grid.php文件中找到以下代码

$this->addColumn('created_at', array( 'header' => Mage::helper('sales')->__('Purchased On'), 'index' => 'created_at', 'type' => 'datetime', 'width' => '100px', ));

步骤2.在第二步中,将代码替换为下面的代码。

$this->addColumn('created_at', array( 'header' => Mage::helper('sales')->__('Purchased On'), 'index' => 'created_at', 'type' => 'datetime', 'width' => '100px', 'filter_index' => 'main_table.created_at', ));

您是否找到我在代码中更改的内容,不是您,确定,让我解释一下。 在此代码中,我添加了以下行:

'filter_index' => 'main_table.created_at',

考虑下一行的用途,在销售订单网格的created_at列中从主集合中找到created_at。但是我们在集合中获得了两次created_at。所以我在下一行中添加了created_at是主表中的一行sales_flat_order不在另一个表中。

就是这个过程

有关更多信息,您可以访问博客

http://www.webtechnologycodes.com/integrity-constraint-violation-1052-column-created_at-in-where-clause-is-ambiguous/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM