Created
June 28, 2010 16:37
-
-
Save abecciu/456069 to your computer and use it in GitHub Desktop.
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
class Ohm::Model | |
@@associations = ::Hash.new { |hash, key| hash[key] = [] } | |
@@references = ::Hash.new { |hash, key| hash[key] = [] } | |
def self.associations | |
@@associations[self] | |
end | |
def associations | |
self.class.associations | |
end | |
def self.references | |
@@references[self] | |
end | |
def references | |
self.class.references | |
end | |
class << self | |
alias_method :orig_collection, :collection | |
alias_method :orig_reference, :reference | |
def collection(*args) | |
orig_collection(*args) | |
associations << args[0] | |
end | |
def reference(*args) | |
orig_reference(*args) | |
references << :"#{args[0]}_id" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment