问题描述
在关系数据库中,我可以有一个表Person
和一个表Hobby
.每个人都可以拥有零个,一个或多个爱好,我还想记录每个人对这些爱好的优先级.
In a relational DB, I could have a table Person
and a table Hobby
. Every person can have zero, one or more hobbies, and I also want to record, say, the priority of those hobbies for every person.
我可以用两个外键PersonFK
和HobbyFK
以及一个普通列Priority
创建一个关系表.
I could create a relationship table with the 2 foreign keys PersonFK
and HobbyFK
, and one plain column Priority
.
在原子论中,为了建模简单的n:m关系(无优先级),我可能会创建类型为Reference
且基数为Many
的属性用于Person
实体.
In datomic, to model a simple n:m relationship (without the priority), I'd probably create an attribute of type Reference
with cardinality Many
, that I'd use for Person
entities.
但是我将如何限定该关系以存储优先级?是否必须类似于关系案例来完成,即通过仅为该关系创建新的实体类型来完成?还是有更好的方法?使用某些元数据工具或其他工具?
But how would I go about qualifying that relation to be able to store the priority? Would it have to be done analogously to the relational case, i.e. by creating a new entity type just for that relation? Or is there any better way? Using some meta data facility or something?
推荐答案
几天前,在Datomic邮件列表中提出了类似的问题:
A similar question was asked on the Datomic mailing list a few days ago:
https://groups.google.com/d/topic/datomic/7uOl-TISdxA/讨论
总而言之,给出的答案是正确的:您需要创建一个关系实体,在该实体上存储额外的信息.
In summary, the answer given there is that you are right: you need to create a relation entity on which to store the extra information.
这篇关于合格的恋爱关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!