Reputation: 14258
The following uses a simplified datomic setup:
:account/user -> string
:account/email -> ref
:email/name -> string
:email/type -> keyword
if I have entity containing account information, it is easy to know that it has email information
(keys <account entity>)
;; => [:account/user :account/email]
(:account/email <account entity>)
;; => <email entity>
But on the flipside, if I look at the keys of the email entity, I do not know that it has linked account information.
(keys <email entity>)
;; => [:email/name :email/type]
(:account/_email <email entity>)
;; => <account entity>
how would one find out that :account/_email
is a valid key without trial and error?
Upvotes: 2
Views: 982
Reputation: 10502
To check if a key is valid you can use:
(.containsKey <email entity> :account/_email)
;; => true
In order to get all valid entity keys including the reverse ones:
(.touch <email entity>)
(keys (.cache <email entity>))
Note that (keys)
called directly on entity returns only forward keys.
Tested on similar schema.
Side note: apart from
(:account/_email <email entity>)
you can also query to get accounts that have linked specified email:
(q '[:find ?a :in $ ?e :where [?a :account/email ?e] ] (db conn) (:db/id <email entity>))
Upvotes: 2
Reputation: 19642
Try the following query (not tested):
(q '[:find ?attrs
:in $ ?e
:where [_ ?attrs ?e]]
my-db my-entity)
Upvotes: 0