{
$sql='select s.name,d.name from student as s,class as c,school as sc,district as d where s.classID=c.id and c.schoolID=sc.id and sc.districtID=d.id';
$connection = Yii::app()->db;
$command = $connection->createCommand($sql);
$results = $command->queryAll();
return $results;
}
This will also create objects for classes and schools, but in the case of using "through" only instances of the Student class will be created. However in both cases all tables will be joined.
Thank you shailesh, Weavora team and andy_s for your quick replies. I’m currently working using Weavora team’s and andy’s solution but found errors in my relationship definitions. Will try shailesh’s solution if all fails.