diff options
author | Matthew Draper <matthew@trebex.net> | 2016-01-11 16:33:16 +1030 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2016-01-12 05:43:58 +1030 |
commit | 5c6d3653830465176ed9d37ec210d55d6ab62852 (patch) | |
tree | 227137b5d13ec8c9d698d0bc53a684b4433b497e /activerecord/lib | |
parent | 8ce0175d50f7fafe648afb8342e17c0898e0ff7f (diff) | |
download | rails-5c6d3653830465176ed9d37ec210d55d6ab62852.tar.gz rails-5c6d3653830465176ed9d37ec210d55d6ab62852.tar.bz2 rails-5c6d3653830465176ed9d37ec210d55d6ab62852.zip |
Skip the STI condition when evaluating a default scope
Given a default_scope on a parent of the current class, where that
parent is not the base class, the parent's STI condition would become
attached to the evaluated default scope, and then override the child's
own STI condition.
Instead, we can treat the STI condition as though it is a default scope,
and skip it in this situation: the scope will be merged into the base
relation, which already contains the correct STI condition.
Fixes #22426.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/core.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/scoping/default.rb | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 1250f8a3c3..475a298467 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -275,7 +275,7 @@ module ActiveRecord def relation # :nodoc: relation = Relation.create(self, arel_table, predicate_builder) - if finder_needs_type_condition? + if finder_needs_type_condition? && !ignore_default_scope? relation.where(type_condition).create_with(inheritance_column.to_sym => sti_name) else relation diff --git a/activerecord/lib/active_record/scoping/default.rb b/activerecord/lib/active_record/scoping/default.rb index cdcb73382f..8baf3b8044 100644 --- a/activerecord/lib/active_record/scoping/default.rb +++ b/activerecord/lib/active_record/scoping/default.rb @@ -122,11 +122,11 @@ module ActiveRecord end def ignore_default_scope? # :nodoc: - ScopeRegistry.value_for(:ignore_default_scope, self) + ScopeRegistry.value_for(:ignore_default_scope, base_class) end def ignore_default_scope=(ignore) # :nodoc: - ScopeRegistry.set_value_for(:ignore_default_scope, self, ignore) + ScopeRegistry.set_value_for(:ignore_default_scope, base_class, ignore) end # The ignore_default_scope flag is used to prevent an infinite recursion |