Courses

How to Structure Databases in Laravel

Laravel.io: Polymorphic All the Things!

avatar

Thank you for the video and explanation. I was wondering - what is advantage of using polymorphic vs many tables (for instance, in case of tbl_likes)? Is it that we can put all the data in one table (tbl_likes) and not it many (tbl_likes_auhtors, tbl_likes_for_articles, etc.)? How does it affect query performance as with time such a table would be huge? Or still, - this way is the best way for saving space in DB?

avatar

From me experience, it's more about FLEXIBILITY than performance. So, one table with potentially adding more data types, without changing the DB structure.

Yes, it is likely to be slower in the long run, with a lot of data, so if you care more about performance than flexibility and reusability of the code, then duplicating data (and all the code around it - Models, etc) instead of polymorphic relations is your preferred option.

avatar
You can use Markdown
avatar
You can use Markdown