Polymorphic Correlation
First, what is polymorphic correlation.
Let's say we have an address table, where the address may be in user or in orders.
Above, just for example, there are a lot of practical examples, such as we want to design a content management system (CMS), our CMS has an article table, a software table. Also asked to support comments, then the ID of our comment table is to refer to the article table or reference software table it?
For the disadvantages of the above example, it seems that there is a suspicion that the pattern of this polymorphic association is going soft in the book. Shortcomings do not say, mainly query trouble, second, can not support foreign key constraints.
Solution Solutions
Cross table
For situations where a foreign key is referenced as multiple tables, you can create a crosstab table. Make address no longer dependent on orders or users.
Advantages:
Referential integrity support.
Disadvantages:
If we want a given address that can only appear once in a crosstab, the composite primary key above has already been done. If you want an address to appear more than once in a crosstab, you can cancel the composite primary key. However, it is not possible to ensure that an address is not present in more than one cross-table, which needs to be implemented in our program code.
In fact, the Polymorphic Association is related to the entity-attribute-value that was mentioned in the previous article.
If the previous use of the class table design, there is no problem at all, the above address, can also rely on inversion. For example, add a addressid in the order table, and add a ADDRESSID solution to the user table.
Assume that the method of class table inheritance is used. Direct the address with a foreign key to the base table is OK there is no such problem. This article in the book is a bit confusing. Now that I've finished, forget it, whatever.
Logical Database Design-Polymorphic Association