我希望扩展关于这个 SO 问题的对话,并在实施方面获得更多细节。
我的要求包括允许管理员在关系上定义标签,其数量是任意的,所涉及的实体是任意的,并且所涉及的实体不是偶然的(即不是Component
实体的一个)。
举一个人为的例子, aUser
可以有很多Projects
. 一个Project
可以有很多Users
。
管理员创建任意数量的标签以分配给每个关系的相关用户,例如to Owner
、Contributor
、VIP
等。User
Project
根据我对这个答案的理解,简单ref
是不够的,我需要创建一个额外的实体,像这样 -
相关Project
属性
:db/ident :project/associations
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
相关User
属性
:db/ident :user/associations
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
相关Association
属性
:db/ident :association/related-ents
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db/ident :association/assoc-id
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/ident :association/tag
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
相关Tag
属性
:db/ident :tag/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
这是我所得到的。我不清楚如何以association
惯用的 Datomic 方式构建实体。
要查找给定的关联关系Project
,包括但不限于Users
,以及在哪里查找关系relationship tag = Contributor
,我应该
1)删除
refs
onProject
+User
并通过检索数据Associations
?即返回association/related-ents
包含的所有关联User-Id = foo
2) 完全不同的东西。
我想我的问题归结为我在哪里存储ref
有效查找?是否db.type
应该使用不同的来代替string
,或者需要不同的构造association
?project/associations
甚至user/associations
refs
是必要的吗?
欣赏任何见解。
更新
经过多一点思考,我想我refs
在各种实体上绊倒了。我想知道我是否可以简单地拥有一个associations/relatedEnts
本身就是一个包含 2 个 Datomic db ids + 标签的 ref 并删除所有其他列出的 attrs。这是理想的吗?
:db/ident :association/relatedEnts
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
:db/ident :association/tag
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one