aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-06-29 08:24:58 -0400
committerGitHub <noreply@github.com>2017-06-29 08:24:58 -0400
commitae751b8f6cfe0fa1846a05eab5f472b852d66d5a (patch)
tree3962564117aef2438a88ca9dc5bd7a11c11c32e7 /activerecord/lib
parent1e798ccb8ff83cc5a014d333e7a1e92e5d146c23 (diff)
parent99912ed92635600eb6b03959c33638cb62f1bdca (diff)
downloadrails-ae751b8f6cfe0fa1846a05eab5f472b852d66d5a.tar.gz
rails-ae751b8f6cfe0fa1846a05eab5f472b852d66d5a.tar.bz2
rails-ae751b8f6cfe0fa1846a05eab5f472b852d66d5a.zip
Merge pull request #29569 from kamipo/fix_to_scoping_is_correctly_restored
Fix to scoping is correctly restored
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/relation.rb2
-rw-r--r--activerecord/lib/active_record/scoping.rb7
2 files changed, 5 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 133c1a6318..52f5d5f3e3 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -333,7 +333,7 @@ module ActiveRecord
# Please check unscoped if you want to remove all previous scopes (including
# the default_scope) during the execution of a block.
def scoping
- previous, klass.current_scope = klass.current_scope, self
+ previous, klass.current_scope = klass.current_scope(true), self
yield
ensure
klass.current_scope = previous
diff --git a/activerecord/lib/active_record/scoping.rb b/activerecord/lib/active_record/scoping.rb
index 7c00e7e4ed..94e0ef6724 100644
--- a/activerecord/lib/active_record/scoping.rb
+++ b/activerecord/lib/active_record/scoping.rb
@@ -10,8 +10,8 @@ module ActiveRecord
end
module ClassMethods
- def current_scope #:nodoc:
- ScopeRegistry.value_for(:current_scope, self)
+ def current_scope(skip_inherited_scope = false) # :nodoc:
+ ScopeRegistry.value_for(:current_scope, self, skip_inherited_scope)
end
def current_scope=(scope) #:nodoc:
@@ -75,8 +75,9 @@ module ActiveRecord
end
# Obtains the value for a given +scope_type+ and +model+.
- def value_for(scope_type, model)
+ def value_for(scope_type, model, skip_inherited_scope = false)
raise_invalid_scope_type!(scope_type)
+ return @registry[scope_type][model.name] if skip_inherited_scope
klass = model
base = model.base_class
while klass <= base