Browse files

Handle :ref/:join in nested insert

  • Loading branch information...
swlkr committed Aug 17, 2018
1 parent 4c7db19 commit 690a9e7974fa01166e4755c0e782d1d5aedc79c0
Showing with 8 additions and 7 deletions.
  1. +8 −7 src/coast/db.clj
@@ -146,17 +146,18 @@
(merge ids results)))
(defn many-rels [m]
(let [schema (coast.db.schema/fetch)]
(select-keys m (->> (:joins schema)
(filter (fn [[_ v]] (string? v)))
(into {})
(select-keys m (->> (coast.db.schema/fetch)
(filter (fn [[_ v]] (and (or (contains? v :db/ref) (contains? v :db/joins))
(= :many (:db/type v)))))
(map first))))
(defn upsert-rel [parent [k v]]
(if (empty? v)
(let [schema (coast.db.schema/fetch)
k-ns (-> schema k :db/joins namespace utils/snake)
join-ns (-> schema k :db/joins name utils/snake)
jk (or (get-in schema [k :db/joins])
(get-in schema [k :db/ref]))
k-ns (-> jk namespace utils/snake)
join-ns (-> jk name utils/snake)
_ (query (connection) [(str "delete from " k-ns " where " join-ns " = ? returning *") (get parent (keyword join-ns "id"))])]
[k []])
(let [k-ns (->> v first keys (filter qualified-ident?) first namespace)

0 comments on commit 690a9e7

Please sign in to comment.