php - count in model scopes() function -


i'm trying count total matches found in scopes, scope works , returns every other column, except count()

   public function scopes()         {             return array(                 'test'=> array(                         'alias' => 'd',                         'select'=> array('d.id, d.picture, d.store, d.address, d.postcode, d.city, d.state, count(*) totalads'),                         'join' => 'join `ads` v',                         'condition'=>'d.is_new="0" , v.pending!="1" , d.id = v.id',                         'group'=>'v.id'                 ),        } 

in view i'm trying data using $data->totalads error when use print_r($data->totalads)

the error property "store.totalads" not defined.

i'm using yii 1.1.15

as error states, totalads not defined.

you define totalads statistical relation in class e.g.

`totalads` => array(self::stat, 'ad', array('id' => 'id'), 'condition' => ... , 'group' => ...) 

you define scope as:

'test' => array(     'with' => array('totalads'),     'together' => true, ); 

alternatively, can create public variable $totalads in store class assigned value of totalads query. however, variable not automatically set outside of scope without additional code.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -