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)]

tonsky10:06:10

@linuss missing? only works in db e a form

tonsky10: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?

tonsky10:06:32

yes, that’s exactly what it is

tonsky10:06:27

actually, you need something slightly different

tonsky10:06:39

because reverse lookups return empty set, not nil

tonsky10:06:43

and missing checks for nil

tonsky10:06:56

you’ll need your own function

linuss10:06:13

Yeah, I figured as much 🙂

linuss10:06:23

Thanks though!

tonsky10:06:43

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

tonsky10:06:54

and pass reverse key in there