diff options
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/association.rb | 12 | ||||
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 4 |
3 files changed, 19 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb index 85343040db..698fd29beb 100644 --- a/activerecord/lib/active_record/associations/preloader/association.rb +++ b/activerecord/lib/active_record/associations/preloader/association.rb @@ -114,8 +114,18 @@ module ActiveRecord @reflection_scope ||= reflection.scope_for(klass) end + def klass_scope + current_scope = klass.current_scope + + if current_scope && current_scope.empty_scope? + klass.unscoped + else + klass.default_scoped + end + end + def build_scope - scope = klass.default_scoped + scope = klass_scope if reflection.type scope.where!(reflection.type => model.base_class.sti_name) diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 4f53280b5c..1026e20f79 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -219,8 +219,10 @@ module ActiveRecord end def klass_join_scope(table, predicate_builder) # :nodoc: - if klass.current_scope && klass.current_scope.values.empty? - klass.unscoped + current_scope = klass.current_scope + + if current_scope && current_scope.empty_scope? + build_scope(table, predicate_builder) else klass.default_scoped(build_scope(table, predicate_builder)) end diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index c5d98e970a..d9e1e5c39c 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -642,6 +642,10 @@ module ActiveRecord "#<#{self.class.name} [#{entries.join(', ')}]>" end + def empty_scope? # :nodoc: + @values == klass.unscoped.values + end + protected def load_records(records) |