Welcome! Please see the About page for a little more info on how this works.

0 votes
ago in On-Prem by

Let's say you have a transaction like:

{:db/id :admin/id,
 :db/unique :db.unique/identity
 :db.install/_attribute :db.part/db}
{:db/id "admin"
  :db/ident :admin/bug
  :admin/id admin-id}

(So both schema & data in one tx)

Normally you would expect idents to work properly - e.g. after that transaction (d/entity db [:admin/id admin-id]) would return the :admin/bug entity. Unfortunately that's not the case (though it used to work in previous versions of datomic) - it returns nil. Splitting the transaction into two makes everything work.

Here's a full repro:

(require '[datomic.api :as d])
(def conn (d/connect (doto (str "datomic:mem://" (d/squuid)) (d/create-database))))
@(d/transact conn [{:db/id "new"
                    :db/ident :admin/id,
                    :db/valueType :db.type/uuid,
                    :db/cardinality :db.cardinality/one,
                    :db/doc "Id of the admin"
                    :db.install/_attribute :db.part/db}])

(def admin-id (d/squuid))

@(d/transact conn [{:db/id :admin/id,
                    :db/unique :db.unique/identity
                    :db.install/_attribute :db.part/db}
                   {:db/id "admin"
                    :db/ident :admin/bug
                    :admin/id admin-id}])

(def db (d/db conn))

(if (some? (d/entity db [:admin/id admin-id]))
  (println "All OK - admin is found by identity")
  (println "Admin identity not there? Let's see the entity: " (d/touch (d/entity db :admin/bug))))

Please log in or register to answer this question.

Welcome to the Datomic Knowledgebase, where you can make features requests, ask questions and receive answers from other members of the community.
...