Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Firstly, CakePHP will automatigally inflect a <code>people</code> table into a <code>people</code> controller and a <code>person</code> model, so you don't need to call it <code>persons</code>. Then I'd call the lookup table <code>relationships</code> rather than <code>persons_persons</code>.</p> <p>I'd call the fields in your relationships table <code>person_id</code>, <code>relation_id</code> and <code>relation_type_id</code>, and then add an underscore in your <code>relationtypes</code> table name so it becomes <code>relation_types</code>.</p> <p>I think this is more semantic.</p> <p>You could still use a hasAndBelongsToMany association, and make use of the automagic "<a href="http://www.cricava.com/blogs/index.php?blog=6&amp;title=modelizing_habtm_join_tables_in_cakephp_&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1" rel="nofollow noreferrer">with</a>" associations offered by CakePHP (1.2 only) to access the additional data in the HABTM table for relation type.</p> <p>However, I'd be tempted to use:</p> <ul> <li><code>Person</code> hasMany <code>Relation</code></li> <li><code>Relation</code> belongsTo <code>Person</code>, <code>Relation</code>, <code>RelationType</code></li> </ul> <p>In your app, is a persons relationship implied by someone else's relationship to them? I.e. if you find Person.id = 1 you might get all their relations, e.g. Person.id 2, 3 and 4. But if you find Person.id 2, you would not automatically get Person.id = 1, unless there was another record in the relations table that represented that relationship.</p> <p>To achieve this, you can set up another assocation:</p> <ul> <li><code>Person</code> hasMany <code>Relation1</code> with foreignKey <code>person_id</code></li> <li><code>Person</code> hasMany <code>Relation2</code> with foreignKey <code>relation_id</code></li> <li><code>Relation</code> belongsTo <code>Person</code>, <code>Relation</code>, <code>RelationType</code></li> </ul> <p>Note, you can achieve this dual relationship with HABTM too.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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