tonsky / datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
Eclipse Public License 1.0
5.5k stars 309 forks source link

Reverse lookup oddity in DataScript 1.3.1 #412

Closed miikka closed 2 years ago

miikka commented 2 years ago

Expanding on #411:

(require '[datascript.core :as d])

(def conn (d/create-conn {:uuid   {:db/unique :db.unique/identity}
                          :child1 {:db/valueType   :db.type/ref
                                   :db/isComponent true}
                          :child2 {:db/valueType   :db.type/ref
                                   :db/isComponent true}}))

(d/transact! conn [{:uuid   "parent"
                    :child1 {:uuid "child1"}
                    :child2 {:uuid "child2"}}
                   {:uuid "child1"}
                   {:uuid "child2"}])

Now pulling with DataScript 1.3.1:

(d/pull @conn '[* :_child1 :_child2] [:uuid "child1"])
=> {:db/id 2, :uuid "child1", :_child1 #:db{:id 1}}

(d/pull @conn '[* :_child1 :_child2] [:uuid "child2"])
=> {:db/id 3, :uuid "child2", :_child1 #:db{:id 1}, :_child2 #:db{:id 1}}

I'm new to DataScript, but having a result for :_child1 when pulling with [:uuid "child2"] does not look right to me. For comparison, here's what I get with DataScript 1.2.10:

(d/pull @conn '[* :_child1 :_child2] [:uuid "child1"])
=> {:db/id 2, :uuid "child1", :_child1 #:db{:id 1}}

(d/pull @conn '[* :_child1 :_child2] [:uuid "child2"])
=> {:db/id 3, :uuid "child2", :_child2 #:db{:id 1}}
tonsky commented 2 years ago

Thank you, it was a bug! Fixed in 1.3.2