Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Thomas_Emad's avatar

Polymorphic Relationships Or Using JSON Column?!

Hello everyone, I am working on a training project which is an educational platform, but in the lecture section I have a big confusion, which is the best?!

The problem is that the instructor can add a text to this lesson and add a video and if he wants to add an exam to it as well. (videos will be out of this server but just save links) I am confused about whether to create a table for lecture basically and then create another table for videos and also one for content(text), etc. Or do I create one table called lecture with only a JSON column?

When looking at it I see the simplest is Json, maybe there will be some problems for the exam because it will be a middleware for the next lesson, but it can be solved. While I see Polymorphic Relationships more complicated because in almost every step I will do three queries (or one big merged all), but it will be more flexible

Maybe in the future attachments will be added, you know that the only constant in any business is constant change. Sorry for the long talk but what do you think is better?

  • I am a simple hobbyist and I don't know which is better, but I will be able to work on it anyway
0 likes
2 replies
vincent15000's avatar
Level 63

Hello,

All ways have pros and cons.

  • it's generally not recommended to use JSON fields if you need to build a query with some condition on these fields, but some other people say that you should never use any JSON field

  • some people say that polymorphic relationships can quickly become complex to use, but I think it's a good approach because it lets some flexibility

Have a look at the great tutorial posted by @tray2.

https://tray2.se/posts/database-design

1 like

Please or to participate in this conversation.