0

我有这个功能:

protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());
        $collection->getSelect()->join('sales_flat_invoice', 'main_table.entity_id = sales_flat_invoice.order_id',array('increment_id'));
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

increment_id 已经存在,所以当我手动运行脚本时,我得到 2 列名称:“increment_id”,所以我想从第二个 $collection 中命名 increment_id。

我试过了:$collection->getSelect()->join('sales_flat_invoice', 'main_table.entity_id = sales_flat_invoice.order_id',array('increment_id AS increment_id2'));但这不起作用:-(

4

1 回答 1

0

尝试这样的事情(尚未测试)

$collection->getSelect()->join(
    array("sfi"=>'sales_flat_invoice'), 
    'main_table.entity_id = sfi.order_id',
    'sfi.increment_id AS increment_id2');

来自http://prattski.com/2010/10/21/magento-collection-join-does-not-allow-table-aliases/

于 2013-04-08T14:01:56.883 回答