I have Product and Categories. A product can be in multiple categories and off course a Category have multiple products.
The Categories can have Subcategories’ which can have Subcategories. I used a Category Model with a circular Foreign Key.
Each Product can have specifications/attributes based in which Categories is.
So the specifications are of the products but depends on the Categories.
I can’t add the specifications as Products attributes because they depend on categories, and the user can change categories.
I can’t add them as attributes per Category because the value are/can be different for each product.
Also an attribute/specification can appear in multiple Categories.
I want also to search for a Product filtering by attributes.
I think I need a separate Attribute Model that is linked (foreign key) to both Product and Category.
Also a way of “protection” in case a Product change categories, a Product and/or a Category is deleted.
What is the optimal approach as flexibility and performance ?