Multi-table relation rule

Suppose I have 3 tables. Schema:




Table A:

Column a_id | Column b_id


Table B:

Column b_id | Column c_id


Table C:

Column c_id



The first column in each table is the primary key. The second column, if exists, is a foreign key referring to the related table.

I know how to write a basic relation rule. For example, in the CActiveRecord class of A




'b' => array(self::BELONGS_TO, 'B', 'b_id');



a_instance->b returns the related class B record of class A instance.

My question is, how to define a relation rule in class A to get related class C record? Does the relation rule support extra joins? If we can do that, is there any benefit of doing so in contrast to defining




'c' => array(self::BELONGS_TO, 'C', 'c_id');



in class B and call a_instance->b->c?

Thank you!

Could anyone help on this? In summary, how to write a relation rule to reference an indirect table/model? Thank you!

Using with() as function




...->with('b', 'b.c')->...



Using property with of CDbCriteria




...

  'with'=>array('b', 'b.c'),

...



or




...

  'with'=>array(

    'b'=>array(

      with=>array('c'),

    )

  )

...



(IIRC)

/Tommy

Did you figure out how to do this?

nice