我不确定我是否正确建模这种类型的关系,也许有人可以提供一些洞察这是否是健全的:
说我们具有典型的父子类型关系,其中每一个父母可以具有许多孩子,但是我们需要跟踪父母的单个(喘息)喜欢的孩子...
表父
- FavoriteChildID
表Child
- ParentID所以链接交叉,其中一个是多对一,另一个是一对一。这是否被认为是好的设计?最好在子表中有一个列,在任何时候只有一行被标记为最喜欢的列?还有什么?
谢谢。
解决方案附加表格如何?
code>表最喜欢(,parent_id ,child_id ,主键(parent_id));这将有助于所有面向收藏的查询。
I'm not sure if I'm modeling this type of relationship correctly, perhaps someone could provide some insight into whether or not this is sound:
Say we have a typical parent-children type relationship where each one parent could have many children, but we need to keep track of the parent's single (gasp) favorite child...
Table Parent
- FavoriteChildIDand
Table Child
- ParentIDso the links criss-cross, where one is a many to one, and the other is one to one. is this considered good design? Would it be better to have a column in the child table where only one row could be flagged a favorite at any time? Something else?
Thanks.
解决方案How about an additional table?
table favourite( ,parent_id ,child_id ,primary key(parent_id) );It would help if for all favourite-oriented queries.
更多推荐
设计表:一对多,一对一同时?
发布评论