From 74861447e40c4cdc043375b4c74a2e601c3a4e37 Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Fri, 17 Feb 2017 11:39:51 -0800 Subject: [PATCH] Accept :db/id in nested maps. (Fixes #178.) (#206) r=rnewman --- src/common/datomish/transact/explode.cljc | 9 +++++---- test/datomish/db_test.cljc | 13 +++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/common/datomish/transact/explode.cljc b/src/common/datomish/transact/explode.cljc index f8cb95a6..d6db0c51 100644 --- a/src/common/datomish/transact/explode.cljc +++ b/src/common/datomish/transact/explode.cljc @@ -57,10 +57,11 @@ (not (db/id-literal? v))) ;; Another entity is given as a nested map. (if (ds/ref? (db/schema db) straight-a*) - (let [other (assoc v (reverse-ref a) eid - ;; TODO: make the new ID have the same part as the original eid. - ;; TODO: make the new ID not show up in the tempids map. (Does Datomic exposed the new ID this way?) - :db/id (db/id-literal :db.part/user))] + (let [other (-> v + (assoc (reverse-ref a) eid) + ;; TODO: make the new ID have the same part as the original eid. + ;; TODO: make the new ID not show up in the tempids map. (Does Datomic exposed the new ID this way?) + (update :db/id #(or %1 (db/id-literal :db.part/user))))] (explode-entity db other)) (raise "Bad attribute " a ": nested map " v " given but attribute name requires {:db/valueType :db.type/ref} in schema" {:error :transact/entity-map-type-ref diff --git a/test/datomish/db_test.cljc b/test/datomish/db_test.cljc index 25e0080f..fedc8764 100644 --- a/test/datomish/db_test.cljc +++ b/test/datomish/db_test.cljc @@ -506,6 +506,19 @@ ExceptionInfo #"\{:db/valueType :db.type/ref\}" (