Fork me on GitHub
#datomic
<
2017-03-05
>
Ethan Miller16:03:06

If I submit a transaction, and then immediately thereafter get the entity id for the entity that I created using d/resolve-tempid; and if I then (in the repl) attempt to pull that entity use d/pull, the value that i get back includes only the :db/id, like so:

{:db/id 17592186045517}
And not the whole set of nested datoms. If i then close out the repl, restart the repl, and reinitiate the db, and then do the pull, then I get the whole thing:
{:db/id 17592186045517,
 :arb/value
 [{:db/id 17592186045519,
   :arb/value [{:db/id 17592186045521, :content/text "Title"}],
   :arb/metadata [{:db/id 17592186045520, :metadata/html-tag :h1}]}
  {:db/id 17592186045522,
   :arb/value [{:db/id 17592186045524, :content/text "Paragraph"}],
   :arb/metadata [{:db/id 17592186045523, :metadata/html-tag :p}]}],
 :arb/metadata [{:db/id 17592186045518, :metadata/html-tag :div}]}
Can someone clue me into why that might be?

rauh16:03:44

@ezmiller77 Are you using db-after for the db?

Ethan Miller16:03:32

@rauh I believe so. I get the entity id after the transaction with this fn:

(defn transact-and-get-id
  "Transact tx and return entity id."
  [conn tx]
  (let [tempid (:db/id tx)
        post-tx @(d/transact conn [tx])
        db (:db-after post-tx)
        entid (d/resolve-tempid db (:tempids post-tx) tempid)]
    entid))

rauh16:03:03

And the pull?

rauh16:03:28

That would explain everything 🙂

Ethan Miller16:03:32

That must be it. I’ve saved db before the transaction!

Ethan Miller16:03:00

Thanks much. Still very much getting used to thinking datomically.

rauh16:03:36

Well pretty much everything in clojure is immutabe, now you have a db that is too! 🙂

rauh16:03:42

I'd probably return [db entid] in your fn.