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,
'Admin',
'user_id'
),
'classes' => array(self::MANY_MANY,
'Class',
'admin(user_id,class_id)'
),
'allClasses'=>array(
self::HAS_MANY,
'Class',
array('class_id'=>'id'),
'with'=>array('studentsCount'),
'through'=>'admin',
'condition'=>'allClasses.state != 0',
));}
And my Classes model has this relations
public function relations() {
return array(
'students'=>array(self::HAS_MANY,'Students','class_id'),
'studentsCount'=>array(self::STAT,'Students','class_id'));}
$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?