From d6d98680120a049f2a7226214a40fa7ecdd178be Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 4 Mar 2016 13:47:19 -0800 Subject: start hiding the `scope_chain` data structure Introduce a predicate method that doesn't need to build a scope chain, but also hides the data structure used for representing the scope chain. --- activerecord/lib/active_record/associations/association.rb | 2 +- activerecord/lib/active_record/reflection.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index d64ab64c99..f7edfbfb5f 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -257,7 +257,7 @@ module ActiveRecord # Returns true if statement cache should be skipped on the association reader. def skip_statement_cache? - reflection.scope_chain.any?(&:any?) || + reflection.has_scope? || scope.eager_loading? || klass.scope_attributes? || reflection.source_reflection.active_record.default_scopes.any? diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 2ca3206f20..f8dffce2f1 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -449,6 +449,10 @@ module ActiveRecord scope ? [[scope]] : [[]] end + def has_scope? + scope + end + def has_inverse? inverse_name end @@ -819,6 +823,12 @@ module ActiveRecord end end + def has_scope? + scope || options[:source_type] || + source_reflection.has_scope? || + through_reflection.has_scope? + end + def join_keys(association_klass) source_reflection.join_keys(association_klass) end -- cgit v1.2.3