aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/preloader/through_association.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-09-02 05:12:42 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-09-02 05:12:42 +0900
commita26cff3c1235c61cd0135bed4ef63d7be452b458 (patch)
treedff1229b4d7551751f6c8f7bda266064b7be960b /activerecord/lib/active_record/associations/preloader/through_association.rb
parent855e5f59f0a990bb35cacbc7e46d02206923551f (diff)
downloadrails-a26cff3c1235c61cd0135bed4ef63d7be452b458.tar.gz
rails-a26cff3c1235c61cd0135bed4ef63d7be452b458.tar.bz2
rails-a26cff3c1235c61cd0135bed4ef63d7be452b458.zip
`values[:includes]` in `reflection_scope` is not compatible with `through_scope`
Without this fix, preloading `:comments_with_include` will cause the following error: ``` % bundle exec ruby -w -Itest test/cases/associations/eager_test.rb -n test_eager_with_has_many_through_join_model_with_include Using sqlite3 Run options: -n test_eager_with_has_many_through_join_model_with_include --seed 1502 E Error: EagerAssociationTest#test_eager_with_has_many_through_join_model_with_include: ActiveRecord::AssociationNotFoundError: Association named 'post' was not found on Post; perhaps you misspelled it? ```
Diffstat (limited to 'activerecord/lib/active_record/associations/preloader/through_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/preloader/through_association.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb
index 874b3fbe85..b469a9ca10 100644
--- a/activerecord/lib/active_record/associations/preloader/through_association.rb
+++ b/activerecord/lib/active_record/associations/preloader/through_association.rb
@@ -86,9 +86,14 @@ module ActiveRecord
if options[:source_type]
scope.where! reflection.foreign_type => options[:source_type]
elsif !reflection_scope.where_clause.empty?
- scope.includes_values = Array(values[:includes] || options[:source])
scope.where_clause = reflection_scope.where_clause
+ if includes = values[:includes]
+ scope.includes!(source_reflection.name => includes)
+ else
+ scope.includes!(source_reflection.name)
+ end
+
if joins = values[:joins]
scope.joins!(source_reflection.name => joins)
end