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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With