$criteria = new CDbCriteria(array('select'=>array('id','title')));
echo Post::model()->find($criteria)->title;
Here is everything OK
$criteria = new CDbCriteria(array('select'=>array('id','title as xxx')));
echo Post::model()->find($criteria)->title;
This returns nothing
$criteria = new CDbCriteria(array('select'=>array('id','title as xxx')));
echo Post::model()->find($criteria)->xxx;
This returns [tt]CException - Property "Post.xxx" is not defined.[/tt]
$criteria = new CDbCriteria(array('select'=>array('id','title as xxx')));
echo Post::model()->find($criteria)->getAttribute('xxx');
This returns [tt]CDbException - Post does not have attribute "xxx".[/tt]
Is there any way to access xxx?
In doc about RAR there is written that we can use select with relations:
Quote
select: a list of columns to be selected for the related AR class. It defaults to '*', meaning all columns. Column names should be disambiguated using aliasToken if they appear in an expression (e.g. COUNT(??.name) AS nameCount).
Throws [tt]CDbException - Active record "table2" is trying to select an invalid column "CONCAT_WS(" - "". Note, the column must exist in the table or be an expression with alias.[/tt]
I was trying it with mysql database.
Am I doing something wrong or there is no possibility to select that expresion neither with lazy nor eager loading?
Please use an array to represent the selected columns (this is undocumented). If you use a string, Yii will attempt to split it into columns according to comma, which gives incorrect result in your case.