Skip to content

Fix upserts containing tempids in tuples #379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Revert last change, update tests
  • Loading branch information
Ash committed Dec 21, 2020
commit 92b580a153fdbd328e55375b78d23cd6795f28e3
9 changes: 3 additions & 6 deletions src/datascript/db.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1100,13 +1100,10 @@
:email {\"ivan@\" 2}
:alias {\"abc\" 3
\"def\" 4}}}"
[db entity tempids]
[db entity]
(if-some [idents (not-empty (-attrs-by db :db.unique/identity))]
(let [resolve (fn [a v]
(let [v (if (coll? v)
(mapv #(get tempids % %) v)
v)]
(:e (first (-datoms db :avet [a v])))))
(:e (first (-datoms db :avet [a v]))))
split (fn [a vs]
(reduce
(fn [acc v]
Expand Down Expand Up @@ -1353,7 +1350,7 @@
(cons (assoc entity :db/id id) entities)))

;; upserted => explode | error
:let [[entity' upserts] (resolve-upserts db entity tempids)
:let [[entity' upserts] (resolve-upserts db entity)
upserted-eid (validate-upserts entity' upserts)]

(some? upserted-eid)
Expand Down
10 changes: 5 additions & 5 deletions test/datascript/test/tuples.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@
[:db/add -2 :player "Federer"]
{:home -1
:away -2}])
(d/transact! conn [{:db/id "p1"
(d/transact! conn [{:db/id "match"
:players ["p1" "p2"]
:game 3}
{:db/id "p1"
:player "Nadal"}
{:db/id "p2"
:player "Federer"}
{:db/id "match"
:players ["p1" "p2"]
:game 3}])
:player "Federer"}])

(is (= 3 (:game (d/entity @conn 3)))
"Upsert successful"))))
Expand Down