[英]SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous Laravel 5.5
[英]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_at
到sales_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不在另一個表中。
就是這個過程
有關更多信息,您可以訪問博客
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.