Skip to content

Instantly share code, notes, and snippets.

@ibdknox
Created December 27, 2012 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibdknox/4391820 to your computer and use it in GitHub Desktop.
Save ibdknox/4391820 to your computer and use it in GitHub Desktop.
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