Created
November 2, 2009 18:58
-
-
Save phinze/224343 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
# <rbriggs> is there any way to put conditions with regards to the source object in | |
# a has_many? for example, I want so say foo.bars and have the bars | |
# association look for bars with an updated_at <= foo.updated_at (note: I | |
# know this can be done with a named_scope in bars.class - but I need this | |
# to be used in as a source association in a :through) | |
class Foo < ActiveRecord::Base | |
has_many :bars | |
def bars_before_me | |
bars.updated_before(self.updated_at) | |
end | |
end | |
class Bar < ActiveRecord::Base | |
belongs_to :bar | |
named_scope :updated_before lambda { |t| :conditions => ["updated_at < ?" t] } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment