Model with different layout based on category
Hello all,
I would like your help on how to achieve this logically taking in account good coding principles, indexing and performance issues.
Imagine the following:
Thanks!
I would like your help on how to achieve this logically taking in account good coding principles, indexing and performance issues.
Imagine the following:
- A model of "Books"
- Books can have different "Categories"
- When creating a Book:
-- If category is Fiction shows fields A, B and C
-- If category is Non-Fiction shows fields D, E, F
- How should I store that data?
-- Should I have all those fields in the database and leave empty depending on category
-- Or should i just have a "meta" column and store it as JSON? - How would I show each field set based on category selected?
Thanks!
Solution
Personnally, I think I would choose to have all fields as columns on the table and simply store
NULL when a field is not applicable to the current item. Storing all fields inside of one JSON column is possible, but keep in mind that it could limit what you can do with the data at the SQL level (searching, filtering, etc.)