I currently have a logs table which has the following rows which use the same order_id
:
log_id | order_id | user | action |
---|---|---|---|
2410 | 1001318004 | test1 | Declined |
2409 | 1001318004 | test1 | Declined |
Inside my app/code/Vendor/Module/Model/ResourceModel/OrderTable/Collection.php
class file I have the following method to set the collection results:
protected function _initSelect()
{
$this->getSelect()->from(['main_table' => $this->getMainTable()]);
$this->getSelect()
->joinLeft(
['logs' => $this->getTable('logs')],
'main_table.increment_id = logs.order_id',
['*','customer_name'=>'CONCAT_WS(" ",main_table.customer_firstname,main_table.customer_lastname)']
);
return $this->filterOrders();
}
where main_table
references the sales_order
table.
but when I view the results in the admin I get the following error:
Item (Magento\Framework\View\Element\UiComponent\DataProvider\Document) with the same ID "1557472" already exists.
The 1557472
refers to the entity ID matching the order for the 1001318004
increment ID.
What I'm looking for, is a way to only get the latest row if there are duplicates in the results.
Cheers guys
"SELECT `main_table`.*, `logs`.*, CONCAT_WS(" ",main_table.customer_firstname,main_table.customer_lastname) AS `customer_name` FROM `sales_order` AS `main_table` LEFT JOIN `logs` ON main_table.increment_id = logs.order_id"
but what I need, is for it to return only the latest rows for duplicate entries.