yii many to many, junction table object graph

Hi, I am taking a Java app and moving it to php. I am experienced in java and used hibernate for the ORM solution.

I have an existing data model to use and am implementing it in Yii.

I need help.

I have many-to-many relationships.

diet -> dietmeal <- meal -> mealfood <- food

junction tables are :



A diet can have many meals & meals can belong to many diets.

A meal can have many foods & foods can belong to many meals.

The Junction tables have fields I need to use in my view and also update. For example: quantity, unit_of_measure.

How can I get these fields all at once, hence loading both the junction table main tables?

In Java Hibernate it’s quite easy.

The sql I want to generate with yii is the following, also having yii populate the entire object graph,

Populate the diet -> dietmeal <- meal -> mealfood <- food

Here is an example of the Output from Hibernate. It executes this sql and fills the object graph.

select distinct diet.*[columns] ,






from test_schema.diet diet

left outer join test_schema.diet_meal dietmeal on diet.id=dietmeal.diet_id

left outer join test_schema.meal meal on dietmeal.meal_id=meals.id

left outer join test_schema.meal_food mealfood on meals.id=mealfood3_.meal_id

left outer join test_schema.food foods on mealfood.food_id=foods.id

left outer join test_schema.food childfoods on foods.id=childfoods.parent_id

left outer join test_schema.schedulable schedulabl on diet.schedulable_id=schedulabl6_.ID

where diet.id=19

order by dietmeal.time asc,

meals.name desc,

foods.calories desc

How can I pull this off in yii? How do I set it up, so I can execute a join like this and get the entire object graph filled.

How to do in Yiii 1.* and 2.*