what’s the best way to find orphan entities, i.e. entities without existing `db.type/ref` relationships?
attribute called :ref
If you need all refs, than maybe something like
(d/q '[:find ?e
:in $ ?ref
:where [?e _ _]
(not [?e ?ref _])]
db refs)where refs come from
(:db.type/ref (:rschema db))thank you! I solved it using avet which should be faster:
(def refs
(into #{}
(comp
(keep (fn [[k v]]
(when (= (:db.type v) :db.type/ref)
k)))
(mapcat (juxt identity sdu/reverse-ref)))
(get-schema)))
(into #{}
(comp (map (comp entity :e))
(remove #(some % refs)))
(datoms :ave :ident))Something like
(d/q '[:find ?e
:where [?e ?a _]
(not [?e :ref _])]
db)
Although it will not be very efficient:ref refers to actual :refs or attributes called :ref?