CLab's avatar
Level 3

One-To-Many Polymorphic vs two relationship columns

Imagine you have a Post model, a Video model and a Comment model similar to the One-To-Many Polymorphic relationship in the docs. Is it better for performance to keep the One-To-Many relationship, or is it better (performance wise and good practice wise) to add two columns for post_id and video_id in the comments table as foreign keys and nullable?

0 likes
1 reply
vincent15000's avatar

I don't think that there is any real performance difference between both solutions.

I would rather use a polymorphic relationship.

Please or to participate in this conversation.