Accept :db/id in nested maps. (Fixes #178.) (#206) r=rnewman
This commit is contained in:
parent
84a80f40f5
commit
74861447e4
2 changed files with 18 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -506,6 +506,19 @@
|
|||
ExceptionInfo #"\{:db/valueType :db.type/ref\}"
|
||||
(<? (d/<transact! conn [{:db/id 101 :aka {:name "Petr"}}])))))))
|
||||
|
||||
(deftest-db test-explode-maps-with-db-id conn
|
||||
(let [{tx0 :tx} (<? (d/<transact! conn test-schema))]
|
||||
(testing "recursively nested maps with specified :db/id are accepted"
|
||||
(<? (d/<transact! conn [{:db/id 101 :name "Oleg"}]))
|
||||
|
||||
(<? (d/<transact! conn [{:db/id 101 :friends {:db/id 201 :name "Ivan" :friends {:db/id 301 :name "Petr"}}}]))
|
||||
(is (= (<? (<datoms-after (d/db conn) tx0))
|
||||
#{[101 :name "Oleg"]
|
||||
[101 :friends 201]
|
||||
[201 :name "Ivan"]
|
||||
[201 :friends 301 ]
|
||||
[301 :name "Petr"]})))))
|
||||
|
||||
(deftest-db test-explode-reverse-refs conn
|
||||
(let [{tx0 :tx} (<? (d/<transact! conn test-schema))]
|
||||
(testing "reverse refs are accepted"
|
||||
|
|
Loading…
Reference in a new issue