Magento在getCollection()中设置AS

时间:2013-04-08 12:39:40

标签: magento collections

我有这个功能:

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'));但这不起作用: - (

1 个答案:

答案 0 :(得分: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/