简体   繁体   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')
);

in a custom magento module that is causing the error 在导致错误的自定义magento模块中

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

commenting out this code allows magento to run correctly, the code is located in an observer 注释掉此代码可使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')
        );
    }

Could anybody advise a fix, this is not my code or my module, and I don't fully understand everything it is doing. 任何人都可以提出修复建议,这不是我的代码也不是我的模块,我不完全了解它所做的一切。

I am guessing it adds a field to a table and populates it then allows you to search using it using the order page. 我猜想它在表中添加了一个字段并填充了它,然后允许您使用订单页面使用它进行搜索。

Thanks in advance. 提前致谢。 -T -T

Take a look at 'sfo_created_at' =>'sfo.created_at' which will rename the sales_flat_order.created_at to sales_flat_order.sfo_created_at (you could also just remove that field from the select) 看一下'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')
);

I have searched every where for this by i am not getting any exact result which will help me in this. 我没有找到任何确切的结果来对此有所帮助的任何地方都在搜索过。 But now i am with the result of why such thing is happening.It's simple as it is saying “Integrity constraint violation: 1052 Column 'created_at' in where clause is ambiguous”, means it is finding a another created_at field. 但是现在我知道发生这种情况的原因。它很简单,因为它说“违反完整性约束:1052列中where子句不明确的'created_at'”,意味着它正在查找另一个created_at字段。 because when we adding or joining the other table then it has also a field named as created_at. 因为当我们添加或联接另一个表时,它还有一个名为created_at的字段。 So what is the solution for this? 那么解决方案是什么?

Any idea…………… 任何想法……………

Its simple just told magento that created_at is of the main_table not of my custom table, how can you do so, i will tell you the full procedure. 它很简单,只是告诉magento,created_at是main_table的而不是我的自定义表的,您怎么做,我将告诉您完整的过程。

Step 1. Find the below code in the sales order grid.php file 步骤1.在销售订单grid.php文件中找到以下代码

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

Step 2. in the second step just replace the code with below one. 步骤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', ));

Have you find what i have changed in the code, not you, ok let me explain. 您是否找到我在代码中更改的内容,不是您,确定,让我解释一下。 in this code i have added the following line: 在此代码中,我添加了以下行:

'filter_index' => 'main_table.created_at',

thinking of what's the use of the following line, here created_at column of sales order grid find created_at from the main the collection .But we are getting twice created_at in the collection.So i have added the following line that this created_at is of the main table sales_flat_order not of the other table. 考虑下一行的用途,在销售订单网格的created_at列中从主集合中找到created_at。但是我们在集合中获得了两次created_at。所以我在下一行中添加了created_at是主表中的一行sales_flat_order不在另一个表中。

That's the process 就是这个过程

for more info you can visit the blog 有关更多信息,您可以访问博客

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

暂无
暂无

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

相关问题 SQLSTATE [23000]:完整性约束违规:1052 order order中的'created_at'列不明确Laravel 5.5 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous Laravel 5.5 SQLSTATE [23000]:完整性约束违规:1052 列“created_at”在 order 子句中不明确 Laravel 8 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous Laravel 8 完整性约束违规:1052 where子句中的列'id'不明确 - Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous Laravel 完整性约束违规:1052 列 'id' in where 子句不明确 - Laravel Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous 违反完整性约束:1052 order子句中的“位置”列不明确 - Integrity constraint violation: 1052 Column 'position' in order clause is ambiguous 违反完整性约束:1052 where子句不明确的列'prof_id'Laravel - Integrity constraint violation: 1052 Column 'prof_id' in where clause is ambiguous Laravel Laravel Eloquent:违反完整性约束:where 子句中的 1052 列“id”不明确 - Laravel Eloquent: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous 如何解决完整性约束违规:1052 列 'id' in where 子句在 laravel 中不明确 - How to solve Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous in laravel SQLSTATE [23000]:违反完整性约束:1052 where 子句中的列“值”不明确 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'value' in where clause is ambiguous Laravel Eloquent SQLSTATE[23000]:违反完整性约束:1052 列...在 where 子句中不明确 - Laravel Eloquent SQLSTATE[23000]: Integrity constraint violation: 1052 Column ... in where clause is ambiguous
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM