[英]database schema for products attributes
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. id
2. category
3. description
Products : 产品 :
1. id
2. category_id
3. product
4. image
5. price
Attributes : 属性 :
1. id
2. attribute
Category_Attributes : Category_Attributes :
1. category_id
2. attribute_id
And the question I have is what tables should I create and what columns shout they have to store different kinds of values, attribute values, products attribute values etc. 我的问题是我应该创建哪些表以及他们必须存储哪些列来存储不同类型的值,属性值,产品属性值等。
Would it be normal to create 3 more tables: 创建3个表是否正常:
Values : 价值观 :
1. id
2. value
Attributes_Values : Attributes_Values :
1. attribute_id
2. value_id
Products_Attributes_Values : Products_Attributes_Values :
1. product_id
2. attribute_id
3. value_id
I've messed up in last tables. 我在最后几桌搞砸了。 What would be better to store and filter?
存储和过滤哪个更好?
What you are trying to achieve is an Entity-Attribute-Value (EAV) or possibly a row modeling solution. 您要实现的是实体 - 属性 - 值 (EAV)或可能的行建模解决方案。 Note that this type of structure is largely frowned upon for a wide variety of pretty good reasons.
请注意,出于各种各样的原因,这种类型的结构在很大程度上是不受欢迎的。
However, I have argued (eg here , here , here , and here ) that EAV is EVIL, except when it isn't. 但是,我已经争论(例如, 这里 , 这里 , 这里和这里 )EAV是EVIL,除非它不是。 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: 考虑这样的设计:
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. 这种设计确实具有EAV强加的所有常见限制。 However, if you want to ask questions like: "Which beads have a diameter of 8mm?"
但是,如果你想问这样的问题:“哪个珠子直径为8mm?” that is pretty straight-forward.
这非常简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.