opike
opike

Reputation: 7575

Groups of groups in cakephp

I'm attempting to find out if there is a cake convention for handling groups belonging to other groups. I have a HABTM relationship between the tables 'entities' and 'entity_groups', but then entity_groups can also be nested with one entity_group belonging to another.

Upvotes: 1

Views: 91

Answers (1)

Justin Yost
Justin Yost

Reputation: 2340

So there seems to be two possible solutions based on what you are asking:

  1. http://book.cakephp.org/view/1339/Tree - CakePHP has a Tree Behavior, for a listing items that are part of another item of the same Model, ie, think of nested lists. CarTypes is a model, SUV is a CarType, SUV Model is a CarType that's in the sub-category of SUV, and thus related to SUV.
  2. http://book.cakephp.org/view/1650/hasMany-through-The-Join-Model Modifying your entity_groups model to operate it as a hasMany relationship to both entities and groups, and link it to a ParentGroup. So each entity_group relationship has a ParentGroup model that enables you to create your own tree like structure for the models.

The best solution is to probably do a combination of these, use the hasMany to modify the Join model and add the Tree Behavior rather than trying to roll your own.

Upvotes: 1

Related Questions