Created
December 27, 2012 20:49
-
-
Save ibdknox/4391820 to your computer and use it in GitHub Desktop.
example of how to handle relation maps.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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