我想知道在jsonb上构建EAV的正确方法是什么。我有Attribute-> Values表格,就像在标准EAV中一样。
CREATE TABLE attribute_values
(
id INTEGER,
attribute_id INTEGER,
value VARCHAR(255)
);
CREATE TABLE attributes
(
id INTEGER,
name VARCHAR(255)
);
Run Code Online (Sandbox Code Playgroud)
值将保存在attributes提起Entity
CREATE TABLE entity
(
id INTEGER,
title TEXT,
attributes JSONB
);
Run Code Online (Sandbox Code Playgroud)
Attribute创建用于控制重复属性的表的类型,并更好地确定它是什么属性。例如,避免:{weight: 100}和{Weight: 100}或{weigh: 100}。Values适用于使用唯一值并包含可用值列表,例如颜色(绿色,红色,白色等)。可以预加载值并将其用于常用搜索。
我看到几个选择:
1.存储格式如
[{"attribute_id":1, "value":5},{"attribute_id":1, value:"text"}]
Run Code Online (Sandbox Code Playgroud)
这里value_id将是custom value像文字或id从Values表。但我不明白如何建立索引的格式,例如,如果Attribute 10将integer
2.仅保留Attribute表(用于控制attribute name)并存储数据,例如:
{"price": …Run Code Online (Sandbox Code Playgroud)