Skip to content

Instantly share code, notes, and snippets.

@tgildea
Created May 31, 2012 21:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tgildea/2846496 to your computer and use it in GitHub Desktop.
Save tgildea/2846496 to your computer and use it in GitHub Desktop.
Monkey Patch to fix ActiveRecord Scope Caching
raise "Check to see if #first and #last bug are fixed" if Rails::VERSION::STRING != "3.2.4"
module ActiveRecord
module Scoping
module Named
extend ActiveSupport::Concern
module ClassMethods
def scoped(options = nil)
if options
scoped.apply_finder_options(options)
else
if current_scope
current_scope.clone
else
scope = relation.clone
scope.default_scoped = true
scope
end
end
end
def scope_attributes # :nodoc:
if current_scope
current_scope.scope_for_create
else
scope = relation.clone
scope.default_scoped = true
scope.scope_for_create
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment