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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -