Created
February 10, 2012 15:14
-
-
Save dorkalev/1790196 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
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