diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2016-03-04 13:47:19 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2016-03-04 13:47:41 -0800 |
commit | d6d98680120a049f2a7226214a40fa7ecdd178be (patch) | |
tree | 2abc10aa499293c6bac61babdab4891ac4e37b38 | |
parent | a327e62c2fef43848d6e86e73778e6c1fd58ad9b (diff) | |
download | rails-d6d98680120a049f2a7226214a40fa7ecdd178be.tar.gz rails-d6d98680120a049f2a7226214a40fa7ecdd178be.tar.bz2 rails-d6d98680120a049f2a7226214a40fa7ecdd178be.zip |
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.
-rw-r--r-- | activerecord/lib/active_record/associations/association.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 10 |
2 files changed, 11 insertions, 1 deletions
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 |