开发者

In CakePHP, how do I set up a "one-to-(one of three)" relationship?

I have three disticnt models, say A, B and C. These are different and couldn't really be merged into one. They share one common element which I have made a separate model, D. What is the best/easiest/standard way to set up this relationship in Cake?

Currently each model A, B, C has an id "D_id" which relate to model D. Though this creates some strange stuff like D being viewed as the "parent model" which isn't the case as it is开发者_JS百科 one of the models A-C.


Each model, A, B, and C should "belongsTo" D.

D should "hasMany" A, B, and C.

This will make it so A, B, and C each have a "D_id" field which references a row in D.

For a GREAT explanation of CakePHP's associations, check out this site.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜