Skip to content

Instantly share code, notes, and snippets.

@baldwindavid
Created August 8, 2009 04:17
Show Gist options
  • Save baldwindavid/164295 to your computer and use it in GitHub Desktop.
Save baldwindavid/164295 to your computer and use it in GitHub Desktop.
module ActiveHash
class Base
def self.has_many(association_id, options = {})
define_method(association_id) do
options = {
:class_name => association_id.to_s.classify,
:foreign_key => self.class.to_s.foreign_key
}.merge(options)
options[:class_name].constantize.send("find_all_by_#{options[:foreign_key]}", id)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment