Udev's avatar
Level 2

Classification for models

I am trying to create proper classification for my models.

I need to classify a product(furniture) by: room ( bedroom, kitchen etc. ), category ( table, chair etc. ), color ( red, blue etc. )

The product can have multiple colors or used in multiple rooms but can have only one type.

I also have another model POST( for a blog ) that can have similar classifications.

What is a good way to approach designing the tables for classification? Should I :

a) Create multiple tables( product_rooms, product_categories, product_colors, post_types, post_categories). This is tedious to manage but has the best performance.

b) Create a categories table which includes a model and type field. The model field will filter what to send to the frontend( eg products page will send only categories where model === APP\MODELS\PRODUCT) so as to populate the filter fields and the type(room, category, color) will group the filter fields. The categories model is related by many to many relationship to both post and product models. This approach is easier to maintain but the code will be "dirty" and the performance may suffer.

Which of these is the better approach? Any other solution or approach to this will also be appreciated.

0 likes
1 reply
jlrdw's avatar
jlrdw
Best Answer
Level 75

A while back martinbean gave a good answer on product variations which could be adapted. tray2 also put an example. Sorry I did not save link, but it's easy to find those past post.

3 likes

Please or to participate in this conversation.