假设我们有以下的局部ER图:可以在CakePHP中使用“语义颠倒”关联,比如Message blongsTo Attachment吗?
注意,attachments
表将随后用于这些消息的,提交,分配,和讲座附件。
问题在于attachments
和messages
,submissions
和assignments
之间的3个一对一关系。根据CakePHP的约定,Message belongsTo Attachment
(和Attachment hasOne Message
)因为Message
包含外键(同样的事情适用于其他2个关系)。当然,说Message hasOne Attachment
(和那个Attachment belongsTo Message
)更有意义。如果我们只有messages
和attachments
,通过将外键移动到attachments
将很容易使“正确定位”的关系。
但问题再次是messages
,submissions
,assignments
,并lectures
具有相同attachments
表关系。获得“”语义上正确的“关系的一种方式是具有4种不同的Attachment
型号:MessageAttachment
,SubmissionAttachment
,AssignmentAttachment
和LectureAttachment
。
假设我们只是在检索某个消息,提交或分配的连接感兴趣,是OK使用这些语义颠倒协会,还是应该适当通过分离Attachment
成4个不同的定位他们模型如上所述?