From 2e018361c7c51e36d1d98bf770b7456d78dee68b Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Thu, 7 Feb 2019 19:40:10 +0900 Subject: Refactor around scoping Don't use `false` as special value to skip to find inherited scope, we could use `skip_inherited_scope = true`, and move `_scoping` back on Relation. --- activerecord/lib/active_record/relation.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/relation.rb') diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index bab00ef065..ab3d6f7222 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -312,12 +312,12 @@ 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 - @delegate_to_klass && klass.current_scope ? yield : klass._scoping(self) { yield } + @delegate_to_klass && klass.current_scope(true) ? yield : _scoping(self) { yield } end def _exec_scope(*args, &block) # :nodoc: @delegate_to_klass = true - instance_exec(*args, &block) || self + _scoping(nil) { instance_exec(*args, &block) || self } ensure @delegate_to_klass = false end @@ -632,6 +632,13 @@ module ActiveRecord end private + def _scoping(scope) + previous, klass.current_scope = klass.current_scope(true), scope + yield + ensure + klass.current_scope = previous + end + def _substitute_values(values) values.map do |name, value| attr = arel_attribute(name) -- cgit v1.2.3