开发者

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

开发者 https://www.devze.com 2023-03-07 06:07 出处:网络
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

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

精彩评论

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