Polymorphism With M:N Relations
The sort of discriminator column used above (the type
field) also comes into play for M:N relations.
Suppose that links and comments could be associated with multiple trips. Somehow, given a trip, we need to know the links and comments. As we saw elsewhere, we can do this via a join entity mapping to a join table, with each entity instance representing one pairing of link/comment to a trip.
And, as with 1:N relations, we have two choices:
- Put all of links and comments in a single table, as we did in the second example above. In that case, our type discriminator goes on that table and in its entity. The join table would only need the ID of the note.
- Have links and comments in separate tables, as we did in the first example. In that case, our link IDs and comment IDs need to be of the same data type (e.g., strings), and we would need a type discriminator in the join table, to be able to distinguish whether a given join entity instance is connecting a trip to a link or to a comment.
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.