I was looking to create an EAV structure for an inventory management system. But I read this answer and decided against it. I am looking to create multiple tables for all my products. But the trouble now have is that all the products will have categories and sub categories( only two tiers ). How can I create tables to reflect the categories for the products. Do I create tables for each category and sub categories. The categories and sub categories need to be searchable.
For example
I will have a product table
Product:
str:name
str:description
a batter table to contain the information of the battery
Battery:
str:volt
str:size
fr:product_id
Doll:
str:material
str:stuffing
fr:product_id
But how do I handle the case when doll and the battery have categories and sub categories of their own? The sub categories and sub categories also needs to be relatable to the particular product while adding a product.
Do I create doll_categories
, doll_sub_categories
, battery_categories
, battery_categories
? I feel like as products are added. Every product should have 3 tables and it may grow to a lot of tables.
What is the best way to handle this situation?
category
to the top level and have asubcategory table
aboveproduct
and havesub_category_id
asfk
onproducts
. I am 99% percent sure about the level of category being just 2 but there is always that 1% I guess :) And also to know which category is for which product during adding a product, I decided to put a product slug in the category table as well, otherwise i would not know what categories are for which product. Is there another way you have in mind? Thanks for the answer. – developernaren Nov 21 '15 at 05:54parentID, ID, category
. Main categories will have NULL as the parentID and sub-categories will have the ID of the main category in parentID. And if you ever need to scale this up, you won't need to add a sub-sub-categories table, you just carry on with the same system. – TheCarver Jun 23 '18 at 14:14