The usual way to set a foreign key constraint is to select the table that the foreign key will point to.
I have a polymorphic relationship between 1 table and a table set.
This means that this table will be related to one of these tables in the set.
eg.
images: person_id, person_type subordinates: id, col1, col2...col9 products: id, colA, colB...colZ
In the above example, if person_type is "subordinate", then person_id must be the foreign key for subordinates.id, and the same goes for products.
So, I wonder if it is possible to have a foreign key for one of the many tables, or you need to specifically indicate which table it points to when you assign it.
This question is for both MySQL and PostgreSQL.
thank
database mysql postgresql polymorphic-associations
never_had_a_name Aug 01 2018-10-18 18:56
source share