$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
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
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
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)
$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. because when we adding or joining the other table then it has also a field named as 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.
Step 1. Find the below code in the sales order grid.php file
$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.
$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.
That's the process
for more info you can visit the blog
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.