diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-02 04:59:27 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-02 04:59:27 +0900 |
commit | 855e5f59f0a990bb35cacbc7e46d02206923551f (patch) | |
tree | a7d4801ebf17bc0ebe5a8ce5f654eaf5f73b38d6 | |
parent | b3bc263a9161aa86a5eb6114a674dc268ca2080f (diff) | |
download | rails-855e5f59f0a990bb35cacbc7e46d02206923551f.tar.gz rails-855e5f59f0a990bb35cacbc7e46d02206923551f.tar.bz2 rails-855e5f59f0a990bb35cacbc7e46d02206923551f.zip |
Don't call `scope.eager_loading?` when `reflection_scope.where_clause` is empty
If `reflection_scope.where_clause` is empty, `scope` isn't changed. So
`scope.eager_loading?` is always false.
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/through_association.rb | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb index de4b847a41..874b3fbe85 100644 --- a/activerecord/lib/active_record/associations/preloader/through_association.rb +++ b/activerecord/lib/active_record/associations/preloader/through_association.rb @@ -85,16 +85,16 @@ module ActiveRecord if options[:source_type] scope.where! reflection.foreign_type => options[:source_type] - else - unless reflection_scope.where_clause.empty? - scope.includes_values = Array(values[:includes] || options[:source]) - scope.where_clause = reflection_scope.where_clause - if joins = values[:joins] - scope.joins!(source_reflection.name => joins) - end - if left_outer_joins = values[:left_outer_joins] - scope.left_outer_joins!(source_reflection.name => left_outer_joins) - end + elsif !reflection_scope.where_clause.empty? + scope.includes_values = Array(values[:includes] || options[:source]) + scope.where_clause = reflection_scope.where_clause + + if joins = values[:joins] + scope.joins!(source_reflection.name => joins) + end + + if left_outer_joins = values[:left_outer_joins] + scope.left_outer_joins!(source_reflection.name => left_outer_joins) end scope.references! values[:references] |