Fork me on GitHub
#datomic
<
2016-08-21
>
jethroksy07:08:08

I have a query that fetches all locations

jethroksy07:08:14

each location belongs to a space

jethroksy07:08:17

(defn get-locations [conn]
  (->> (d/q '[:find [(pull ?locations [*]) ...]
              :in $
              :where [?locations :location/id]]
            (d/db conn))
       (map c/db->loc)))

jethroksy07:08:35

I was assuming that the wild card for the pull would recursively fetch attributes for the space

jethroksy07:08:51

but I still get a result like this:

jethroksy07:08:54

actual: ({:address "19 Foobar Street",
            :postal-code "S890123",
            :space {:db/id 277076930200554}}
           {:address "19 Barbaz Street",
            :postal-code "S123456",
            :space {:db/id 277076930200554}})

pesterhazy08:08:51

I believe the space needs to be marked as :db/isComponent true: http://blog.datomic.com/2013/06/component-entities.html

jethroksy08:08:34

ah I'll play around with that, thanks!

jethroksy08:08:12

fwiw I think I had to touch the return results

hans08:08:49

you can also recursively pull referenced entities, i believe the syntax was [* {:space [*]}]

hans08:08:04

it is documented, though.

pesterhazy08:08:14

touching is giving up 🙂

robert-stuttaford09:08:24

also, d/touch only works with d/entity results

jethroksy09:08:16

yup, I ended up with

jethroksy09:08:18

(defn get-locations [conn]
  (->> (d/q '[:find [(pull ?locations [* {:location/space [*]}]) ...]
              :in $
              :where [?locations :location/id]]
            (d/db conn))
       (map c/db->loc)))

jethroksy09:08:12

I was mislead into thinking it would recursively pull my referenced entities

jethroksy09:08:23

> Wildcard Specifications The wildcard specification * pulls all attributes of an entity, and recursively pulls any component attributes:

jethroksy09:08:14

:release/media seemed to be recursively pulled, as well as :medium/tracks

Ben Kamphaus19:08:00

@jethroksy just to note this, that documentation specifies component attributes only, and those attributes are set with isComponent/true :: https://github.com/Datomic/mbrainz-sample/blob/master/schema.edn#L266 — also see the blog post: http://blog.datomic.com/2013/06/component-entities.html (though that’s in the context of touch, same applies to pull wildcard pull spec).