Should Categories be it's own resource or model attribute?
I have a question on database design. Say I have a Post model that has/belongs to a category (out of about 20 categories or so). I am thinking of two options that have their own merits.
1. Category as own resource with Post belong_to it
- this allows listing of all categories and posts under a category easy
- however, entries will most probably be done once at the start and then left to be
hence the other option
2. Categories as an attribute of Post
- scoping Post by categories is trivial still
- categories can be picked from a constant list
Would love to hear any of your comments on this how would you go about doing it.
Old post I know but it's quite a general question so will add my thoughts.
My decision making has always come down to whether there will only ever be one
category, or potential multiple
categories. For the singular, you can probably just add a column in your model, but for multiple entries, you might want to create a seperate category model, and then reference the two via a joins table.
This approach is very common for tags for example, but to be honest, I've started using it in many areas that can have multiple entries. e.g. flavours in coffee or different gin brands served by a bar.
At the end of the day, it's all just a type of tagging.
Thanks for your answer! Never actually thought of it that way. Come to think of it, it makes the most sense. Cheers!