Getting aliased property from CActiveRecord result using CDbCriteria

I have a result object set out like this…

$criteria            = new CDbCriteria;

$criteria->select    = 'SUM(credit_amount) AS balance';

$criteria->condition = 'user_id = :id';

$criteria->params    = array(':id'=>$user->id);

$result = Transaction::model()->find($criteria);

I’ve aliased the SUM as balance but cannot access the balance property the obvious way i.e.


An exception is thrown stating the table column doesn’t exist. How do I access the ‘balance’ property of the result set?

Just declare it as a public member of the model class.


That worked. Thanks Tommy