Good afternoon all,
So I’m building a “small” web app to track books read, shows and movies watched, comics enjoyed, etc. But I’ve hit a bit of “devblock” in that I’m not sure how to I should properly map out the tables.
Initially, I wanted to do a single “Items” table that would hold a primary binary_id key and a type and a few other common data points which would lead you to some distinct tables for each type. But then as I was reading the Ecto docs I stumbled on the polymorphism section about how that’s discouraged for a number of good reasons.
Then I figured I’d do Single Table Inheritance and have an “Items” table with all the columns needed but that would lead to a lot of nulls bouncing around which I wasn’t a fan of. I could use schemas to hide them away so maybe this is the right way but I wanted to explore other options as well.
My current favorite is the separate tables for each “Item” type and then an “Items” abstract table. There are only a very few times in the initial design of my application where “Items” is used so I don’t believe the DB would be hampered by having to join the distinct tables too often.
But perhaps utilizing embedded schemata is the way to go? I’ve seen the polymorphic embed package.
The relevant post where I got these ideas is linked here. It’s a fairly exhaustive list of pros and cons but I was wondering if anyone else has gone through this process and had any wisdom on mapping inheritance in databases. I may just have to settle on one option and test it to see if it fits my needs but was hoping someone had something they could add.
Thanks for any insight in advance.