Relational query - recursive relationship


I’ve started recently my adventure with yii and encounter a problem for piece of code below:

$menus = Menu::model()->with('','page')->findAll()

gives me error about duplicate aliases.

Menu model has subMenus array of Menu models. Now Menu model has page model therefore all child subMenus have page model as well.

I want to get all the menus with its submenus already with loaded related page objects. Is it possible to be done using relational query?

I don’t really know if this will work, but you can give it a try.

Call the relation like this:

$menus = Menu::model()->with('subMenus')->findAll();

And when you define it, add a ‘with’ index with ‘pages’ (the name of the relation that gets the pages) value, like this:

public functions relations() {

 return array(