I’m trying to select some different column with formatting like:
Article::model()
->findAll(array(
'select' => "DATE_FORMAT(`t`.`article_date`, '%b %D %Y') AS `t`.`display_date`, (`t`.`col1` + `t`.`col2`) AS `t`.`relevance`",
'order' => "`t`.`relevance` DESC"
));
When Executing above code I’m getting this error message:
Active record "Article" is trying to select an invalid column "'%b %D %Y') AS `t`.`display_date`".
Note, the column must exist in the table or be an expression with alias.
It seems like it’s treating the comma in DATE_FORMAT as a column separator, which suggests that the query isn’t being built correctly. I suspect that Yii is doing some processing which is splitting the string on the comma.
See if defining the select clause as an array helps:
The documentation says that the select attribute expects an array of column names, so this might not be the right way to handle this.
EDIT:
Delving into the source code here, Yii does indeed split the string on the comma character. From what I can see, passing it as an array should work. It seems to only do further processing if it can’t find a ‘(’ character.
Seems It’s does not allowing database stored function. When I used with function ‘FORMAT_DATE’ then the query was without function like ‘., t.article_date, ‘%b %D %Y’) AS display_date, .’