如何使用EAV来设计基于类、属性和值的对象?
我想设计一个系统,用户可以灵活地定义类、对象、属性和值,并且对象可以绑定到类,然后获取类的属性,然后为每个属性提供值。
我想为某些属性设置多个值,例如,如果一个对象有 2 个地点的 2 个电话号码(电话和号码是位置类的属性),我想知道 1 个对象的哪个电话对应哪个地点?什么是最好的设计?
我的设计如下:
- 类:
Id
,Name
- 对象:
Id
,Name
- ClassObject:
Id
、ClassId
、ObjectId
- 属性:
Id
、名称
、ClassId
- 值:
Id
、ClassObjectId
、属性Id
,值
I want to design a system that a user can define class, object, attribute and value flexibly and objects can bound to class(es) then get attributes of class and then have values for each attribute.
I want to set multiple value for some attribute for example if an object has 2 phone number for 2 place (phone and number are attributes of Location Class) I want to know that which phone is for which place for 1 object? What is the best designing?
My design is like bellow:
- Class:
Id
,Name
- Object:
Id
,Name
- ClassObject:
Id
,ClassId
,ObjectId
- Attribute:
Id
,Name
,ClassId
- Value:
Id
,ClassObjectId
,AttributeId
,Value
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答您的设计问题:
为了将电话和地点关联起来,您必须使用附加类“地点”并将属性“电话”赋予类“地点”。 “location”类的一个实例可以有 2 个“place”类的实例。
这要求您有另外两个表:
Btw。您的元模型很有趣:它非常灵活,允许一个对象属于多个类。
因此你可以表达:
对象“Arnold Schwarzenegger”属于以下类别:BodyBuilder、Immigrnt、演员、书籍作者、商人、政治家。
另一方面,类之间没有继承/子类型关系。
您的属性定义中似乎没有显式的值类型声明。
Answer to your design question:
In order to associate the phone and place you have to use an additional class "place" and give the attribute "phone" to class "place". An instance of class "location" may have 2 instances of class "place".
This requires that you have another two tables:
Btw. Your metamodel is interesting: it is very flexible by allowing an object to belong to multiple classes.
Hence you can express:
Object "Arnold Schwarzenegger" belongs to classes: BodyBuilder, Immigrnt, Actor, Book Author, Businessman, Politician.
On the other hand you have no inheritance / subtype relationship between classes.
It seems that you have no explicit value type declaration in your attribute definition.