Skip to content

Instantly share code, notes, and snippets.

@dorkalev
Created February 10, 2012 15:14
Show Gist options
  • Save dorkalev/1790196 to your computer and use it in GitHub Desktop.
Save dorkalev/1790196 to your computer and use it in GitHub Desktop.
require 'active_support/all'
class AktivRekord
def self.has_many what
define_method(what.to_s.pluralize) do
what.to_s.classify.constantize.find_by_id(self.send("#{what.to_s.singularize}_id"))
end
end
end
class Person < AktivRekord
has_many :books
def book_id
5
end
end
class Book < AktivRekord
def self.find_by_id(id)
[Book.new, Book.new]
end
end
x = Person.new
puts x.books
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment