Cakephp Newbie Model question
I have a table familiars , a table mages and a table mages_familiars where I keep which familiar belongs to which Mage.
How can I model this cross reference table?
开发者_运维百科Thanks in advance
You don't need the intermediary table unless it's possible that a familiar can belong to multiple mages and mages can have multiple familiars (a HABTM relationship). In that case the table should have fields id
(int), created
(datetime), modified
(datetime), mage_id
(int) and familiar_id
(int). Also, the table should be named familiars_mages
.
If a familiar can belong to only one mage, a familiar belongsTo a mage and a mage hasMany familiars. The familiars table should have a mage_id
field.
If a familiar can belong to only one mage, and a mage can have only one familiar, you can use a hasOne relationship. In that case either the mages table has a familiar_id
field or the familiars table has a mage_id
field.
精彩评论