A set of foreign keys, where all but one are NULL

What is the name of the method for using a set of foreign keys in a table where all but one are NULL for a given row?

In other words, each row requires a foreign key for one (and only one) of n different possible tables, so you have all the necessary foreign keys, but all but one are NULL.

(Django users can recognize this as an alternative to using a universal foreign key)

+4
source share
2 answers

The description term that you are describing is an Exclusive Arc .

Instead, I prefer to make one foreign key that refers to a common super-table of your n different parent tables.

See my other answers for polymorphic associations:

+5
source

It would be easier with an example, but a common way to unravel is to simply find a common supertype for these tables. Suppose we have tables Book, Article, Magazine , and now the table should have a foreign key for these tables. Using the common supertype Publication resolves this. See here the model and a similar question / answer.

+2
source

Source: https://habr.com/ru/post/1299107/


All Articles