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)?
tri
(tri - Tommy Riboe)
3
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.
/Tommy
Thanks Tommy, that did it.
mikl
(Mike)
5
In that case it’s also sufficient to write:
Groups::model()->with ('labels.attribs')->findAll()