Skip to content

Instantly share code, notes, and snippets.

@abecciu
Created June 28, 2010 16:37
Show Gist options
  • Save abecciu/456069 to your computer and use it in GitHub Desktop.
Save abecciu/456069 to your computer and use it in GitHub Desktop.
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