0

このコードを取得しました (in: app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php):

protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());
        $collection->getSelect()->join('sales_flat_order_item', '`sales_flat_order_item`.order_id=`main_table`.entity_id', array('skus'  => new Zend_Db_Expr('group_concat(`sales_flat_order_item`.sku SEPARATOR "<br>")')))->group('sales_flat_order_item.entity_id');
        $collection->getSelect()->join('sales_flat_order_payment', 'main_table.entity_id = sales_flat_order_payment.parent_id',array('method'))->group('sales_flat_order_payment.parent_id');
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

COL 1 または COL 2 の下の行にコメントすると、これは正常に機能しますが、両方を機能させたいのですが、これはどのように行われますか? (同時に使用すると、エラーが発生しますIntegrity constraint violation: 1052 Column 'entity_id' in group statement is ambiguous:)

回答付きで更新:

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->getSelect()->join('sales_flat_order_item', '`sales_flat_order_item`.order_id=`main_table`.entity_id', array('skus'  => new Zend_Db_Expr('group_concat(`sales_flat_order_item`.sku SEPARATOR "<br>")')));
    $collection->getSelect()->join('sales_flat_order_payment', 'main_table.entity_id = sales_flat_order_payment.parent_id',array('method'))->group('main_table.entity_id');
    $this->setCollection($collection);
    return parent::_prepareCollection();
}
4

2 に答える 2

2

答えはエラーにあります。グループを適用するテーブルを特定できません。テーブルを明示的に定義する必要があります。

...->group('sales_flat_order_item.entity_id');
于 2013-04-08T11:32:31.247 に答える
0

echo (string) $collection->getSelect(); を使用してクエリをエコーし​​ます。ここで単純な sql クエリを取得します。データベースでそのクエリを起動して確認し、希望どおりの結果が得られているかどうかを確認します。最後になりましたが、グループも問題を引き起こします。magento で group() break getSelectCountSql を使用して、以下のリンクを見てください。

于 2013-04-08T11:07:32.203 に答える