aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-09-11 21:25:41 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-09-11 21:25:41 +0900
commit4895e5cfc753a7145b02edeb48a80824dda57cba (patch)
treeaeb902e620ebced609acd5f35facc807b0b38d17 /activerecord
parent334c4c533f427e126acb1edb561ad6fabea216de (diff)
downloadrails-4895e5cfc753a7145b02edeb48a80824dda57cba.tar.gz
rails-4895e5cfc753a7145b02edeb48a80824dda57cba.tar.bz2
rails-4895e5cfc753a7145b02edeb48a80824dda57cba.zip
Move `scoping` handling into klass level from relation
I'd like to use this `scoping` handling on klass level to address unwanted internal scoping issues.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation.rb5
-rw-r--r--activerecord/lib/active_record/scoping/default.rb9
2 files changed, 9 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index c4e48cdb67..36e72dcd8a 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -315,10 +315,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(true), self unless @delegate_to_klass
- yield
- ensure
- klass.current_scope = previous unless @delegate_to_klass
+ @delegate_to_klass ? yield : klass._scoping(self) { yield }
end
def _exec_scope(*args, &block) # :nodoc:
diff --git a/activerecord/lib/active_record/scoping/default.rb b/activerecord/lib/active_record/scoping/default.rb
index 8c612df27a..6caf9b3251 100644
--- a/activerecord/lib/active_record/scoping/default.rb
+++ b/activerecord/lib/active_record/scoping/default.rb
@@ -31,7 +31,14 @@ module ActiveRecord
# Post.limit(10) # Fires "SELECT * FROM posts LIMIT 10"
# }
def unscoped
- block_given? ? relation.scoping { yield } : relation
+ block_given? ? _scoping(relation) { yield } : relation
+ end
+
+ def _scoping(relation) # :nodoc:
+ previous, self.current_scope = current_scope(true), relation
+ yield
+ ensure
+ self.current_scope = previous
end
# Are there attributes associated with this scope?