aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rw-r--r--activerecord/lib/active_record/base.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 19a7965429..99930e7697 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -428,6 +428,10 @@ module ActiveRecord #:nodoc:
class_attribute :default_scopes, :instance_writer => false
self.default_scopes = []
+ # Boolean flag to prevent infinite recursion when evaluating default scopes
+ class_attribute :apply_default_scope, :instance_writer => false
+ self.apply_default_scope = true
+
# Returns a hash of all the attributes that have been specified for serialization as
# keys and their class restriction as values.
class_attribute :serialized_attributes
@@ -1261,11 +1265,14 @@ MSG
self.default_scopes = default_scopes + [scope]
end
+ # The apply_default_scope flag is used to prevent an infinite recursion situation where
+ # a default scope references a scope which has a default scope which references a scope...
def build_default_scope #:nodoc:
+ return unless apply_default_scope
+ self.apply_default_scope = false
+
if method(:default_scope).owner != Base.singleton_class
- # Use relation.scoping to ensure we ignore whatever the current value of
- # self.current_scope may be.
- relation.scoping { default_scope }
+ default_scope
elsif default_scopes.any?
default_scopes.inject(relation) do |default_scope, scope|
if scope.is_a?(Hash)
@@ -1277,6 +1284,8 @@ MSG
end
end
end
+ ensure
+ self.apply_default_scope = true
end
# Returns the class type of the record using the current module as a prefix. So descendants of