Created
September 8, 2012 01:10
-
-
Save knewter/3671084 to your computer and use it in GitHub Desktop.
MacroReflection-esque ActiveRecord::Relation does what now?
This file contains hidden or 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 MacroReflectionRelationFacade < SimpleDelegator | |
def initialize(proxied) | |
super(proxied) | |
end | |
def target | |
self | |
end | |
end |
This file contains hidden or 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 'macro_reflection_relation_facade' | |
class Person < ActiveRecord::Base | |
has_many :person_school_links | |
# Relationships | |
def person_school_links(status = :status_active) | |
MacroReflectionRelationFacade.new(PersonSchoolLink.where(person_id: self.id).send(status)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment