CakePHP定义HABTM / ManyToMany关系中的其他字段? [英] CakePHP defining additional fields in HABTM/ManyToMany relationship?
本文介绍了CakePHP定义HABTM / ManyToMany关系中的其他字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上我想在CakePHP中重现这个:
Basically I would like to recreate this in CakePHP:
或者换句话说,我的中间表具有定义关系类型的额外字段。
or in other words, my intermediary table to have extra fields defining the type of relationship.
如何在CakePHP中设置?
How do I set this up in CakePHP?
您可以使用示例:
model company:
id
name
person_id
model person:
id
name
model company_person:
company_id
person_id
position
thanx
推荐答案
数据在HABTM中,使用2有多个关系。所以如果A HABTM B,然后设置为:A hasMany A_B,B有多个A_B,A_B属于A,A_B属于B. AFAIK,HABTM的蛋糕支持不是很灵活。
if you want to have additional data in HABTM, use 2 hasMany relationships instead. So if A HABTM B, then set it up as: A hasMany A_B, B hasMany A_B, A_B belongsTo A, A_B belongsTo B. AFAIK, Cake support for HABTM is not very flexible.
这篇关于CakePHP定义HABTM / ManyToMany关系中的其他字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文