Skip to content

Instantly share code, notes, and snippets.

@ibdknox ibdknox/core.clj
Created Dec 27, 2012

Embed
What would you like to do?
example of how to handle relation maps.
(defn rel-map
[ent sub-ent type opts]
(assoc-in ent [:rel (:name sub-ent)]
(delay
(create-relation ent sub-ent type opts))))
(defmacro has-one
"Add a has-one relationship for the given entity. It is assumed that the foreign key
is on the sub-entity with the format table_id: user.id = address.user_id
Opts can include a key for :fk to explicitly set the foreign key.
(has-one users address {:fk :addressID})"
[ent sub-ent & [opts]]
(if (symbol? sub-ent)
`(rel ~ent (var ~sub-ent) :has-one ~opts)
`(rel-map ~ent ~sub-ent :has-one ~opts)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.