G'day,
I've been switching my existing code over to Korma, and I've been creating a namespace for each of my entities, so I can try and group them logically together.
The only thing I'm having trouble with, is that when you define a relationship, it ends up resolving the sub entity to the current namespace:
I believe it's in the rel function in core.clj:
(defn rel
[ent sub-ent type opts]
(let [var-name (-> sub-ent meta :name)
cur-ns *ns*]
(assoc-in ent [:rel (name var-name)]
(delay
(let [resolved (ns-resolve cur-ns var-name)
sub-ent (when resolved
(deref sub-ent))]
(when-not (map? sub-ent)
(throw (Exception. (format "Entity used in relationship does not exist: %s" (name var-name)))))
(create-relation ent sub-ent type opts))))))
What is the reason for this?
I'm currently preferring to have an entity defined like:
(ns database.iso.isos
(require (database.iso [customers :as customers]))
(use korma.core))
(defentity iso
(pk :ixIso)
(table :Iso)
(belongs-to customers/customer {:fk :ixCustomer})
(database connection/production))
Which won't work, Clojure is fairly new to me, and I'm not that good at programming in general, so I was wondering if there was a better way for me to layout my entities?