【问题标题】:Magento set AS in getCollection()Magento 在 getCollection() 中设置 AS
【发布时间】:2013-03-30 13:03:39
【问题描述】:

我有这个功能:

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

【问题讨论】:

    标签: magento collections


    【解决方案1】:

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

    $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/

    【讨论】:

      猜你喜欢
      • 2015-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多