Skip to content

Commit

Permalink
Fixed regression when unique ref tempid was not resolved during trans…
Browse files Browse the repository at this point in the history
…action (closes #295)
  • Loading branch information
tonsky committed Mar 11, 2019
1 parent 4b5d232 commit bef1aba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# WIP

- Fixed regression when transient indexes were mutated and iterated during single tx (#294)
- Bumped persistent-sorted-set to 0.1.2 (throw if transient set is mutated and iterated at the same time)
- Fixed regression when transient indexes were mutated and iterated during single tx (#294).
- Bumped persistent-sorted-set to 0.1.2 (throw if transient set is mutated and iterated at the same time).
- Fixed regression when unique ref tempid was not resolved during transaction (#295).

# 0.18.1

Expand Down
10 changes: 5 additions & 5 deletions src/datascript/db.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,11 @@
(and (ref? db a) (tx-id? v))
(recur (allocate-eid report v (current-tx report)) (cons [op e a (current-tx report)] entities))

(and (ref? db a) (tempid? v))
(if-some [vid (get tempids v)]
(recur report (cons [op e a vid] entities))
(recur (allocate-eid report v (next-eid db)) es))

(tempid? e)
(let [upserted-eid (when (is-attr? db a :db.unique/identity)
(:e (first (-datoms db :avet [a v]))))
Expand All @@ -1244,11 +1249,6 @@
(let [eid (or upserted-eid allocated-eid (next-eid db))]
(recur (allocate-eid report e eid) (cons [op eid a v] entities)))))

(and (ref? db a) (tempid? v))
(if-some [vid (get tempids v)]
(recur report (cons [op e a vid] entities))
(recur (allocate-eid report v (next-eid db)) es))

(= op :db/add)
(recur (transact-add report entity) entities)

Expand Down
12 changes: 11 additions & 1 deletion test/datascript/test/transact.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,17 @@
:where [?e :name ?n ?t]
[?e :age ?a]] @conn)))))

(deftest test-tempid-ref-295
(let [db (-> (d/empty-db {:ref {:db/unique :db.unique/identity
:db/valueType :db.type/ref}})
(d/db-with [[:db/add -1 :name "Ivan"]
[:db/add -2 :name "Petr"]
[:db/add -1 :ref -2]]))]
(is (= #{[1 :name "Ivan"]
[1 :ref 2]
[2 :name "Petr"]}
(tdc/all-datoms db)))))

(deftest test-resolve-eid-refs
(let [conn (d/create-conn {:friend {:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}})
Expand Down Expand Up @@ -300,7 +311,6 @@
(is (= (into {} (d/entity @conn tx-id))
{:prop4 "prop4"})))))))


(deftest test-transient-294
"db.fn/retractEntity retracts attributes of adjacent entities https://github.com/tonsky/datascript/issues/294"
(let [db (reduce #(d/db-with %1 [{:db/id %2 :a1 1 :a2 2 :a3 3}])
Expand Down

0 comments on commit bef1aba

Please sign in to comment.