Fork me on GitHub
#datomic
<
2019-01-12
>
Andres01:01:21

Anybody know how to use missing? with a reverse lookup? Is this supposed to work? [(missing? $ ?l :account/_licenses)]

Andres01:01:20

Also, is there a reason why I can't use 2 missing? statements in an or? (or [(missing? $ ?a :account/licenses)] [(missing? $ ?a :account/email)])

Andres01:01:22

Error CompilerException java.lang.RuntimeException: Unable to resolve symbol: $ in this context

jdkealy01:01:10

@andres paste the full query

Andres01:01:29

(d/q '[:find [?a ...]
       :in $
       :where
       (or [(missing? $ ?a :account/licenses)]
           [(missing? $ ?a :account/email)])]
     db)

Andres01:01:00

ah, @jdkealy are you referring to the Error or missing? reverse lookup?

Andres01:01:12

I would like to use the reverse lookup to find the transitions (?t) that do not have a current license (?l). [?t :license-transition/current-license ?l]

(d/q '[:find [?l ...]
       :in $
       :where
       [?l :member-license/status _]
       [(missing? $ ?l :license-transition/_current-license)]]
     db)

Andres17:01:58

Can anybody help?

marshall17:01:52

@andres you dont need reverse lookup in query, just turn the clause around

Andres17:01:46

How would you do that with missing??

Andres17:01:14

Sorry, I don't quite see it. Do you mind showing me with an example or use my own query above?

marshall17:01:28

Im not sure what youre trying to do. Id need to understand the data model and entity relationships

Andres17:01:37

I would like to use the reverse lookup to find the transition entities (?t) that do not have a current license entities(?l). Ex. Relationship [?t :license-transition/current-license ?l] Desired query. Is this a valid way to use missing?

(d/q '[:find [?l ...]
       :in $
       :where
       [?l :member-license/status _]
       [(missing? $ ?l :license-transition/_current-license)]]
     db)
Does this clear up the model and it's relationships?

marshall17:01:34

[(missing? $ ?t :license-transition/current-license)]

marshall17:01:59

Find all entities that dont have that attr set ^

Andres17:01:09

Cool, what about the second issue

marshall17:01:24

Then do whatever additional joins you need to narrow down those entities

marshall17:01:44

Whats the second issue?

Andres17:01:20

A query with or with two missing? brings up an error. Account entities have licenses entities and an email string.

(d/q '[:find [?a ...]
       :in $
       :where
       (or [(missing? $ ?a :account/licenses)]
           [(missing? $ ?a :account/email)])]
     db)
Error CompilerException java.lang.RuntimeException: Unable to resolve symbol: $ in this context

Andres17:01:45

@marshall sorry it took me a bit, was going through airport security.

Andres18:01:21

Is there a reason why I can't have two missing??

jaihindhreddy-duplicate18:01:16

^ Shouldn't the (or ...) be wrapped in a vector?

Andres18:01:33

Hmm, I've usually done without.

Andres18:01:29

Doesn't seem like you need a vector.

👍 5
Andres18:01:53

Hmm, might be because or implicitly targets the db $, and missing? gets confused??? (guessing here) Similar to how you can't have embedded anonymous functions that use %. Not sure how that would be resolved though...

marshall19:01:30

I’ll have to look into that one next week

marshall19:01:43

it may be related to the implicit $ though

benoit20:01:42

@andres Not sure why the query returns an error but but you will need to bind ?a to something outside of the or anyway and it looks like it is working with or-join:

(d/q '[:find [?a ...]
       :where
       [?a :account/id]
       (or-join [?a]
                [(missing? $ ?a :account/licenses)]
                [(missing? $ ?a :account/email)])]
       db)
I bind ?a with :account/id but you should replace this clause with whatever you need to only return account entities.

Andres21:01:50

Cool! I'll take a look at or-join and try it out. Thanks!