 
 ;;; attach lhs to all rhses such that any change to an rhs initiates an
 ;;; attempt to [re]join it to the lhs and vice versa.
-(defn- join-views [join-fn join-pk [lhs-model lhs-pk-key lhs-fk-keys joined-model] & rhses]
+(defn- join-views [join-fn join-pk joined-model [lhs-model lhs-pk-key lhs-fk-keys] & rhses]
   (let [rhs-count (count rhses)
         ;; need 2 pass initialisation
 	indeces (atom [(lhs-init rhs-count) 

  (reify
   View
   ;; singleton changes
   (on-upsert [_ upsertion] ((swap*! indeces lhs-upsert lhs-pk-key lhs-fk-keys upsertion join-fn join-pk joined-model) []) nil) ;TODO - pass in views to notifier
   (on-delete [_ deletion]  ((swap*! indeces lhs-delete  lhs-pk-key lhs-fk-keys deletion join-fn join-pk joined-model) []) nil) ;TODO - pass in views to notifier
   ;; batch changes
   (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)))


  (^String toString [this] name)
  )

(defn join-model [name joined-model joins join-fn join-pk]
  (let [state (apply join-views join-fn join-pk joined-model joins)]
    (->JoinModel name state (atom []))))

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