Unable to query by original db/ident once an alias was created

Is it possible to query by the original ident which was set for an entity once an alias ident was set to the entity? Once the alias was set it is possible to get the same entity using https://docs.datomic.com/pro/clojure/index.html#datomic.api/entity for both idents but the entity can’t be found using https://docs.datomic.com/pro/clojure/index.html#datomic.api/query where a search is executed by original ident. Would be good to have clarification about this somewhere in the docs about possible restrictions applied on entities that have aliases

Steps to reproduce the issue:

(require '[datomic.api :as d])
(d/create-database "datomic:mem://test8")
(def conn (d/connect "datomic:mem://test8"))

(def post-schema [
                       :db/ident :Post/title.version.1
                       :db/valueType :db.type/ref
                       :db/cardinality :db.cardinality/one
(d/transact conn post-schema)

[[:db/add :Post/title.version.1 :db/ident :Post/title1]])

(def entityByAlias1_1 (d/entity (d/db conn) :Post/title1))
(def entityByOriginalIdent_1 (d/entity (d/db conn) :Post/title.version.1))
(def queryByOriginalIdent_1 (d/q '[:find
 :in $
 [?e :db/ident :Post/title.version.1]
(d/db conn)))


You can see the variable queryByOriginalIdent_1 is empty

Datomic team, please do not pay attention to my request where I ask to delete the post

1 Like

d/entid resolves idents using the “a-historical” element index that remembers old ident assertions. (d/entid db :Post/title.version.1) will do what you want. You can use it directly in a query also like [(datomic.api/entid $ :Post/title.version.1) ?id].

1 Like