Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

How can I get the value for aggregate query in Yii if the aggregate value not an attribute on the activerecord class?

$criteria = new CDbCriteria(); $criteria->select = 'type , seen, count(1) As counts'; $criteria->condition = 'mb = :mb AND deleted = false AND archived = false'; $criteria->params = array(':mb'=>$mb); $criteria->group = 'type ,seen'; $counters = $this->findAll($criteria); the problem is How can I get the value for (counts ) if its not as attribute on class? I try to $counters[0]->counts but not worked

user-image
Question added by Khadijah Shtayat , Technical Lead , Opensooq
Date Posted: 2013/11/27
Sohaib AlZyoud
by Sohaib AlZyoud , Senior Software Engineer , Secured Services Systems (SSSIT)

You cant access the value unless its an attribute on the model (or) and attribute on the table,

 

quick solution :

on the model file add new attribute (member variable) and use it in the query

 

class xxModel {

public $countOfX;

}

 

$criteria = new CDbCriteria(); $criteria->select = 'type , seen, count(1) As countOfX'; $criteria->condition = 'mb = :mb AND deleted = false AND archived = false'; $criteria->params = array(':mb'=>$mb); $criteria->group = 'type ,seen'; $counters = $this->findAll($criteria);

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.