我希望能延長關於this SO question的對話並獲得更多關於實現的細節。Datomic中的註釋關係
我的要求包括允許管理員定義關係上的標籤,其數量是任意的,涉及的實體是任意的,並且涉及的實體不是偶然的(即不是實體的Component
)。
對於一個人爲的例子,User
可以有很多Projects
。 A Project
可以有許多Users
。
管理員可以創建任意數量的標籤以分配給相關用戶的每個關係,例如Owner
,Contributor
,VIP
等,對於User
到Project
。
據我瞭解的this answer,一個簡單的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
這是據我已經得到了。我不清楚如何以慣用的Datomic方式構造association
實體。
要找到一個給定的Project
關聯關係,包括但不限於Users
,以及找關係,其中relationship tag = Contributor
,我應該
1)刪除該
refs
上Project
+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 +標記並放棄所有其他列出的attrs的ref。這是理想嗎?
: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
你考慮確定各角色的單獨的項目屬性(貢獻者,業主等)? –
是的,我確實考慮過。這條路線失去了實體關係的任意靈活性。再次做作,但例如,管理員出現並決定添加項目和位置之間的關係,使其成爲尋寶。可能的標籤是'起點','午餐','終點線'或任何數量的無法預先預測的任意標籤。 – nrako