user635818
user635818

Reputation: 99

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.

Upvotes: 5

Views: 7740

Answers (1)

dmanners
dmanners

Reputation: 2072

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)

Upvotes: 4

Related Questions