Magento加入不同的表

Ahs*_*san 3 php mysql left-join magento

我的Grid.php文件中有以下代码:

function _prepareCollection () {
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->joinLeft(
    array('sfog' => 'sales_flat_order_grid'),
    'main_table.entity_id = sfog.entity_id',
    array('sfog.shipping_name','sfog.billing_name')
);
$collection->getSelect()->joinLeft(
    array('sfo'=>'sales_flat_order'),
    'sfo.entity_id=main_table.entity_id',
    array(
        'sfo.customer_email',
        'sfo.weight',
        'sfo.discount_description',
        'sfo.increment_id',
        'sfo.store_id',
        'sfo.created_at',
        'sfo.status',
        'sfo.base_grand_total',
        'sfo.grand_total'
    )
);
Run Code Online (Sandbox Code Playgroud)

我想添加表sales_order_item,但如果我添加此表,我会收到此错误:

具有相同id"119"的Item(Mage_Sales_Model_Order)已经存在

无论如何围绕这个?

Max*_*Max 5

假设你正在加入soi意义sales_order_item,请逐一soi.item_id进行

$collection->getSelect()->group('soi.item_id');
Run Code Online (Sandbox Code Playgroud)