/gist:9d7f86e27014ef5df280 Secret
Created
February 20, 2009 17:55
Revisions
-
lukeredpath created this gist
Feb 20, 2009 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ module RailsExtensions module HasManyThroughWithScope def has_many_with_scope(association, options={}) if (through = options[:through]) && (scope = options.delete(:scope)) if conditions = through.to_s.classify.constantize.send(scope).proxy_options[:conditions] scope_conditions = conditions.inject({}) do |scope_conditions, (key, value)| scope_conditions["#{through}.#{key}"] = value scope_conditions end options[:conditions] = (options[:conditions] || {}).merge(scope_conditions) end end has_many_without_scope(association, options) end end end ActiveRecord::Base.extend(RailsExtensions::HasManyThroughWithScope) ActiveRecord::Base.metaclass.instance_eval do alias_method_chain :has_many, :scope end