Fork me on GitHub
#datascript
<
2017-06-30
>
linuss08:06:25

Does anybody know why this query returns all functiontypes, regardless of whether or not :offer/function exists?

[:find ?label ?value
                :where
                [?i :functiontype/functiontype ?label]
                [?i :functiontype/functiontypeid ?value]
                [?i :functiontype/blocked false]
                [?j :functions/functiontypeid ?value]
                [?j :functions/functionid ?fid]
                [(missing? $ _ :offer/function ?fid)]

Niki10:06:10

@linuss missing? only works in db e a form

Niki10:06:03

@linuss try [(missing? $ ?fid :offer/_function)]

linuss10:06:56

@tonsky What's that underscore there? Does datascript allow some sort of reverse lookups?

Niki10:06:32

yes, that’s exactly what it is

Niki10:06:27

actually, you need something slightly different

Niki10:06:39

because reverse lookups return empty set, not nil

Niki10:06:43

and missing checks for nil

Niki10:06:56

you’ll need your own function

linuss10:06:13

Yeah, I figured as much 🙂

linuss10:06:23

Thanks though!

Niki10:06:43

(defn missing?
  [db a v]
  (empty? (get (de/entity db v) a)))
something like thta

Niki10:06:54

and pass reverse key in there