What is the name for the technique of using a set of foreign keys in a table where all but one are NULL for a given row?
In other words, each row needs a foreign key to one (and only one) of n different possible tables so you actually have all the necessary foreign keys but all but one are NULL.
(users of Django may recognize this as an alternative to using a Generic开发者_JAVA百科 Foreign Key)
The term for the design you're describing is Exclusive Arc.
Instead, I prefer to make one foreign key that references a common super-table of your n different parent tables.
See my other answers for polymorphic associations:
- Possible to do a MySQL foreign key to one of two possible tables?
- Referencing foreign keys in the same column
- Why can you not have a foreign key in a polymorphic association?
- In a StackOverflow clone, what relationship should a Comments table have to Questions and Answers?
- How to handle an “OR” relationship in an ERD (table) design?
It would have been easier with a example, but a common way to untangle this is simply to find a common super-type for those tables. Suppose that we have tables Book, Article, Magazine
and now a table has to have foreign key to these tables. Using a common super-type Publication
resolves this. See here for the model and the similar question/answer.
精彩评论