Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've found that HABTM relationships are best for simple relationships, not complex ones like you are describing above. The idea of an HABTM relationship is to make the join table almost invisible so you do not have to maintain the extra foreign keys. It works well for simple cases.</p> <p>In your case, you have the equips table that would join to all of the other aspects of your system. In the design, you need a starting point. I would imagine the "user" would be that starting point and the user would have many equips. You may limit a user to having only one equip, which would almost lend itself to merging the user and equips tables into a single one.</p> <p>In any case you need to start by defining the rules.</p> <p>User -> HasOne -> Equips Equips -> BelongsTo -> User</p> <p>According to your database deisgn, it looks like the following relationships would be made. Equips -> BelongsTo -> Hat Equips -> BelongsTo -> Pant Equips -> BelongsTo -> Wep Wep -> HasMany -> Equips ...</p> <p>To build the best application, what I would suggest is to build every possible relationship and look at the resulting data set from each view...</p> <pre><code>$this-&gt;User-&gt;recursive = 2; pr($this-&gt;User-&gt;find("first"); </code></pre> <p>From there I would redesign the tables to get a structure that looks good and makes sense. Then trim out the unnecessary relationships.</p> <p>Also spend some time looking into binding and unbinding models. This will allow you to more effectively customize the data and relationships once the database design is stable. </p> <p>Hope this helps a bit. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload