我有一个角色实体,它引用:role/members
中的用户实体。
我需要返回所有给定:role/name
成员的所有用户,例如:
(ns myns.core
(:require
[datomic.api :as dat]))
(def conn (dat/connect "datomic:mem://my-datomic"))
(defn tempid
[]
(dat/tempid :db.part/user))
(def first-user-tempid (tempid))
(def second-user-tempid (tempid))
(def third-user-tempid (tempid))
(def first-user {:db/id first-user-temp-eid
:user/name "first user"})
(def second-user {:db/id second-user-temp-eid
:user/name "second user"})
(def third-user {:db/id third-user-temp-eid
:user/name "third user"})
(def first-role {:db/id (tempid)
:role/name "first role"
:role/members [first-user third-user]})
(def second-role {:db/id (tempid)
:role/name "second role"
:role/members [second-user third-user]})
(def tx-report @(dat/transact conn
[first-user
second-user
third-user
first-role
second-role]))
(defn members-of
[db role-names]
....)
(->> ["first role"
"second role"]
(members-of (:db-after tx-report))
(map :user/name)) => ["third user"]