Find elements from sub categories of related models

Hi I’m new to yii and I really need help

I’ve been doing a couple of succesful things the last past days with Yii relations, but I can’t find how to achieve this :

I have 3 related models, let’s say

  • Continent

  • Country

  • City

I want to fetch all the cities of a given continent and display it in its view, I have no problem getting all the countries I use this code in the actionView method.


       $country=new CDbCriteria();

       $country->with = array('continent'=>array('select'=>'*'),);


       $country->params=array(":id"=> $id);

       $this->render('view', array('countries'=> Country::model()->findAll($country)));

What I want is to find all the cities of the countries of that continent, what should I do next please…

did you try:

       $criteria=new CDbCriteria();

       $criteria->with = array('country'=>array('width'=>array('continent')),);


       $criteria->params=array(":id"=> $id);

       $this->render('view', array('countries'=> City::model()->findAll($criteria)));

Thanks a lot Zaccaria ! it works fine, so easy, I knew I was missing something, I didn’t know I could use two relations this way.

Thanks again !