how to setup relations between three tables


I’m a bit lost as to how to define the relations of the three models as well as the criteria of the CActiveDataProvider of ‘b’.

These are the three tables:


a_id name


b_id name


a_id b_id

where b belongs to a (a can have many b, but b can only belong to one a)

I’m trying to get to where from view of ‘a’ I can click on a link that takes me to index listing of all the ‘b’ that belongs to ‘a’.

Please help!


You need only two tables for this, why using three?

Great question. We are currently using YII to build an extranet for our partners, which shares the same database as our website. The existing data structure, although works well for our internal use, does not meet the needs of our partners. As a medium term solution, we decided to add an assignment table.

Hmm, okay.

You can use ‘through’ option in HAS_MANY.

A HAS_MANY B through Assignment.

See details here.