 (s/defschema DenormalizeOp
   (s/enum :upsert :delete))
 
-(defn deref-target-entity
-  [kw]
-  (let [var (ns-resolve (-> kw namespace symbol)
-                        (-> kw name symbol))]
-    @var))
+(defn- deref-target-entity
+  "given a namespace qualififed symbol or keyword referring to a
+   var with an Entity, return the Entity... otherwise return whatever
+   is given"
+  [entity-var-ref]
+  (if (or (keyword? entity-var-ref)
+          (symbol? entity-var-ref))
+    (deref
+     (ns-resolve (namespace entity-var-ref) (name entity-var-ref)))
+
+    entity-var-ref))
 
 (s/defn foreign-key-val
   "returns [fk fk-val] for the denorm relationship"

   target-record :- t/RecordSchema
   denorm-op :- DenormalizeOp]
  (let [[fk fk-val :as fk-vals] (foreign-key-val source-entity source-record denorm-rel)
        fk-map (into {} fk-vals)
        denorm-vals (->> (:denormalize denorm-rel)
                         (map (fn [[scol tcol]]
                                [tcol (get source-record scol)]))

   source-entity :- Entity
   target-entity :- Entity
   source-record :- t/RecordSchema
   denorm-rel-kw :- s/Keyword
   denorm-rel :- t/DenormalizationRelationshipSchema
   denorm-op :- DenormalizeOp]
  (with-context deferred-context
