开发者

Cakephp Newbie Model question

开发者 https://www.devze.com 2023-04-08 11:36 出处:网络
I have a table familiars , a table mages and a table mages_familiars where I keep which familiar belongs to which Mage.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号