Skip to content

Commit bef1aba

Browse files
committed
Fixed regression when unique ref tempid was not resolved during transaction (closes #295)
1 parent 4b5d232 commit bef1aba

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# WIP
22

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

67
# 0.18.1
78

src/datascript/db.cljc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,11 @@
12351235
(and (ref? db a) (tx-id? v))
12361236
(recur (allocate-eid report v (current-tx report)) (cons [op e a (current-tx report)] entities))
12371237

1238+
(and (ref? db a) (tempid? v))
1239+
(if-some [vid (get tempids v)]
1240+
(recur report (cons [op e a vid] entities))
1241+
(recur (allocate-eid report v (next-eid db)) es))
1242+
12381243
(tempid? e)
12391244
(let [upserted-eid (when (is-attr? db a :db.unique/identity)
12401245
(:e (first (-datoms db :avet [a v]))))
@@ -1244,11 +1249,6 @@
12441249
(let [eid (or upserted-eid allocated-eid (next-eid db))]
12451250
(recur (allocate-eid report e eid) (cons [op eid a v] entities)))))
12461251

1247-
(and (ref? db a) (tempid? v))
1248-
(if-some [vid (get tempids v)]
1249-
(recur report (cons [op e a vid] entities))
1250-
(recur (allocate-eid report v (next-eid db)) es))
1251-
12521252
(= op :db/add)
12531253
(recur (transact-add report entity) entities)
12541254

test/datascript/test/transact.cljc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,17 @@
250250
:where [?e :name ?n ?t]
251251
[?e :age ?a]] @conn)))))
252252

253+
(deftest test-tempid-ref-295
254+
(let [db (-> (d/empty-db {:ref {:db/unique :db.unique/identity
255+
:db/valueType :db.type/ref}})
256+
(d/db-with [[:db/add -1 :name "Ivan"]
257+
[:db/add -2 :name "Petr"]
258+
[:db/add -1 :ref -2]]))]
259+
(is (= #{[1 :name "Ivan"]
260+
[1 :ref 2]
261+
[2 :name "Petr"]}
262+
(tdc/all-datoms db)))))
263+
253264
(deftest test-resolve-eid-refs
254265
(let [conn (d/create-conn {:friend {:db/valueType :db.type/ref
255266
:db/cardinality :db.cardinality/many}})
@@ -300,7 +311,6 @@
300311
(is (= (into {} (d/entity @conn tx-id))
301312
{:prop4 "prop4"})))))))
302313

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

0 commit comments

Comments
 (0)