Skip to content

Instantly share code, notes, and snippets.

@glv
Created February 18, 2013 15:40
Show Gist options
  • Save glv/4978287 to your computer and use it in GitHub Desktop.
Save glv/4978287 to your computer and use it in GitHub Desktop.
Rails 3.0.5 initializer that monkeypatches in lieu of https://github.com/glv/rails/commit/93389371d17472023d4884643e755725dce9aa6d
require 'active_record'
module ActiveRecord
module Associations
# This fix allows the association extension methods to work when used in combination
# with built-in Arel scoping methods (where, joins, etc.) and *also* with named scopes
# defined on the target class.
class AssociationProxy
def with_scope_with_extensions(*args, &block)
result = with_scope_without_extensions(*args, &block)
return result unless Relation === result
result.extending(*Array.wrap(@reflection.options[:extend]))
end
alias_method_chain :with_scope, :extensions
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment