 (defn- lhs-upserts [old-indeces i ks vs join-fn])
 (defn- lhs-deletes [old-indeces i ks vs join-fn])
 
-(defn- lhs-view [indeces i keys join-fn joined-model]
+(defn- lhs-view [indeces i lhs-fk-keys join-fn joined-model]
   (reify
    View
    ;; singleton changes
-   (on-upsert [_ upsertion] ((swap*! indeces lhs-upsert keys upsertion join-fn joined-model) []) nil) ;TODO - pass in views to notifier
-   (on-delete [_ deletion]  (swap! indeces lhs-delete keys deletion join-fn) nil)
+   (on-upsert [_ upsertion] ((swap*! indeces lhs-upsert lhs-fk-keys upsertion join-fn joined-model) []) nil) ;TODO - pass in views to notifier
+   (on-delete [_ deletion]  (swap! indeces lhs-delete lhs-fk-keys deletion join-fn) nil)
    ;; batch changes
-   (on-upserts [_ upsertions] (swap! indeces lhs-upserts keys upsertions join-fn) nil)
-   (on-deletes [_ deletions]  (swap! indeces lhs-deletes keys deletions join-fn) nil)))
+   (on-upserts [_ upsertions] (swap! indeces lhs-upserts lhs-fk-keys upsertions join-fn) nil)
+   (on-deletes [_ deletions]  (swap! indeces lhs-deletes lhs-fk-keys deletions join-fn) nil)))
 
 ;; TODO: return a pair - first is notification fn, second is new-indeces - use swap*! to apply
 

;;--------------------------------------------------------------------------------
;; this layer encapsulates access to both lhs and rhs at the same time...

(defn- derive-joins [lhs rhs-indeces keys join-fn]
  (map
   (fn [args] (apply join-fn lhs args))
   (permute [[]] (rhses-get rhs-indeces keys lhs))))

;;--------------------------------------------------------------------------------

(defn- lhs-upsert [old-indeces keys lhs join-fn joined-model]
  (let [new-indeces (lhs-assoc old-indeces keys lhs)
	joins (derive-joins lhs (rest new-indeces) keys join-fn)]
    [new-indeces (fn [_] (on-upserts joined-model joins))]))

;;; TODO

	lhs-indeces (first old-indeces)
	lhses (lhses-get lhs-indeces i fk)
	rhs-indeces (rest new-indeces)
	joins (mapcat (fn [lhs] (derive-joins rhs-indeces lhs-fk-keys lhs join-fn)) lhses)
	]
    [new-indeces (fn [_] (on-upserts joined-model joins))]
    ))
