I have the following DB relations:
Building hasMany Shape
Appartment hasOne Shape
Building hasMany Appartment
Shape belongsTo Building & Appartment
Now, in the Shape model I would like to retrieve all shapes belonging to a certain building. This includes the shapes belonging to the appartments belonging to this certain building.
E.g.
Building 'X'
There are 4 shapes directly linked to building X via the belongsTo Building relation.
Shape->Building
And there are 2 shapes directly linked to 2 appartments via the belongsTo Appartment relation. These 2 appartments again are directly linked to Building X via the belongsTo Building relation. Thus these 2 shapes are indirectly linked to building X.
Shape->Appartment->Building
I can’t seem to get my head around this, help is much appreciated.
Use CakePHP’s Containable Behavior.