sql - IfNULL function in yii does not work -
in model wrote:
$criteria->select = ' ( select avg( ifnull( tr.stars_rating_type_id , 0) ) stars_rating_type_id '.$tableprefix.'tour_review tr tr.tour_id = t.id , tr.status = \'a\' ) reviews_avg_rating ';
and error :
active record "tour" trying select invalid column "( select avg( ifnull( tr.stars_rating_type_id". note, column must exist in table or expression alias.
the reason add "ifnull( ..., 0)" function in subquery escape "null" in result set.
without have make additional verification , set 0 in case of null.
if test raw sql " select ( select avg( ifnull( tr.stars_rating_type_id, 0) ) stars_rating_type_id..."
works ok, problem yii side. how fix ?
yii 1.1.14
thanks!
take on manual:
http://www.yiiframework.com/doc/api/1.1/cdbcriteria
the select param receive columns search, not hole query
Comments
Post a Comment