I am trying to design a database for nested categories of products, e.g. "men/shoes/sandals", "women/shoes", or "men/jeans".
I can model it with two entities Category
and Product
. The "subcategory" Category-to-Category relationship is many-to-many. Every Category
has zero or many subcategories. Every Category
has zero or many parent Categories
. For example, "jeans" is a subcategory of categories "men" and "women", category "men" has subcategories "jeans" and "shoes", etc. I believe Category
entities form a DAG (direct acyclic graph) and can be modeled with a "join table".
In this model a Product
belongs to a path in this DAG. For example, a product can belong to path "men/shoes/sandal" but not to category "men" or category "sandal". Does it make sense ? How would you model this Product-to-Category relationship ?
Another problem is the order of products. I would like to display products in category men/shoes
in some particular order. How would you suggest store this order in the database ?