Can't Eager Fetch Statistical Query In Model Relation

Hi everyone,

first of all, im having this same problem.

User Model have this relations.

public function relations() {

return array(

'admin' => array(self::HAS_MANY,




'classes' => array(self::MANY_MANY,










	'condition'=>'allClasses.state != 0',


And my Classes model has this relations

public function relations() {

                return array(



$classes = User::model()->findByPk(1)->allClasses;

foreach ( $classes as $class)


         echo $class->studentsCount;


This should use eager loading aproach to get studentsCount for each class, but instead is still using lazy loading.

Can this be done? or should I use a different aproach to get the data eager loaded?