database schema for products attributes

前端 未结 1 1794

I want to implement products filtering in category and I have questions about the right DB schema. For now I have the following tables:

Categories:

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-31 07:04

    What you are trying to achieve is an Entity-Attribute-Value (EAV) or possibly a row modeling solution. Note that this type of structure is largely frowned upon for a wide variety of pretty good reasons.

    However, I have argued (e.g. here, here, here, and here) that EAV is EVIL, except when it isn't. One of those rare exceptions is in the case of a product catalog where you are tracking the properties of products and where those properties aren't that interesting (to your system!) except insofar as you need to retrieve these and print them out on a product web page or a comparison grid, etc.

    Consider a design like this:

    enter image description here

    What you are doing in a model like this is describing which attributes products in a given category ought to have, what values those attributes might have, and then which values each specific product does have for each attribute.

    This design does have all of the usual limitations that EAV imposes. However, if you want to ask questions like: "Which beads have a diameter of 8mm?" that is pretty straight-forward.

    0 讨论(0)
提交回复
热议问题