Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento, addAttributeToSelect, alias

how to make an alias (AS) when using collections.

$collection->addAttributeToSelect('total_qty')

It can be done this way:

$collection->getSelect()->columns(array('alias'=>'total_qty'))

but then I will get both "total_qty" and "total_qty AS alias", in the query.

Thanks.

like image 904
user635818 Avatar asked Oct 08 '22 04:10

user635818


1 Answers

If you collection is an instance of Mage_Core_Model_Resource_Db_Collection_Abstract then you can use the function addFieldToSelect.

This function takes two attributes. Firstly it takes the field you want to add to the select and secondly it takes an alias.

public function addFieldToSelect($field, $alias = null)
like image 65
dmanners Avatar answered Oct 12 '22 01:10

dmanners