A little more advanced relational query

Let’s say I have 3 tables related.

Groups -> (HAS_MANY) Labels -> (HAS_MANY) attributes

To get the groups with their labels I would use:

Model_name::model()->with ('labels')->findAll()

Is there a way to retrieve all records (groups+labels+attributes)?

Anyone on this?

Have you tried this? Assuming an ‘attribs’ relationship declaration in Label.

Groups::model()->with ('labels', 'labels.attribs')->findAll()

For a complete list of the whole set you will need a nested foreach.

An alternative is to start the query from Attribs.

Attribs->(BELONGS_TO)Labels->(BELONGS_TO)Groups, that is.


Thanks Tommy, that did it.

In that case it’s also sufficient to write:

Groups::model()->with ('labels.attribs')->findAll()