Sample Header Ad - 728x90

Polymorphic Association - is it bad?

9 votes
2 answers
5117 views
In the following schema: Collections Upvotes Reports Upvotes Reviews Upvotes I'm tempted to have a single Upvotes table with a single "entityId" column that stores either the CollectionId, ReportId, or ReviewId. There will also be an enum for Type - storing either collection, report, or review. The entityId will always be required, and the logic will always make sure that inserts enforce uniqueness across each type. The benefits of this is that adding another type is just a matter of expanding the enum. Everything will live on a single table with no redundancy. The cost seems to be the added complexity on the logic side, which is contained to the one place in my application logic that inserts new entities into the table. Practically speaking, is there anything wrong with this approach? What would be some other reasons to avoid this?
Asked by RobVious (191 rep)
Dec 8, 2013, 05:01 PM
Last activity: Jun 4, 2024, 12:44 PM