Fork me on GitHub
#datomic
<
2018-07-22
>
henrik11:07:28

(d/q {:query '{:find [?id ?title (pull ?id [:journal/id])]
                 :where [[?id :journal/title ?title]]}
        :args [(d/db conn)]})
` Gives me the following error:
ExceptionInfo processing rule: (q__1114 ?id ?title ?id), message: processing clause: [?id :journal/title ?title], message: java.lang.ArrayIndexOutOfBoundsException: 2  clojure.core/ex-info (core.clj:4739)

marshall12:07:51

You can only have each entity once in a find expression. In your original example, you have ?id and the pull on ?id. You could pull [:journal/title :db/id] if you want to pull both.

henrik12:07:52

Ah, yes, I can see ?id appearing twice there. java.lang.ArrayIndexOutOfBoundsException threw me off. Pull looks like a function, so intuition suggests that ?id would be consumed by it and of no concern for the surrounding bits. There’s clearly some magic going on here.

henrik12:07:57

Thank you!

henrik11:07:55

Dropping the initial ?id in the :find clause works fine though:

(d/q {:query '{:find [?title (pull ?id [:journal/id])]
               :where [[?id :journal/title ?title]]}
      :args [(d/db conn)]}
[["International Bulletin of Mission Research"
  {:id [{:identity/type "publisher-id",
         :identity/value "IBM",
         :db/id 22918220369363020}
        {:identity/type "hwp",
         :identity/value "spibm",
         :db/id 22918220369363024}]}]]