diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-02 07:17:56 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-02 07:36:09 +0900 |
commit | 82bfe3bf115e7d4d6f5f5b40f8ab32a61148da67 (patch) | |
tree | 753476301018ac701a1b137acaf37a4e76d4d158 /activerecord/test/cases | |
parent | a26cff3c1235c61cd0135bed4ef63d7be452b458 (diff) | |
download | rails-82bfe3bf115e7d4d6f5f5b40f8ab32a61148da67.tar.gz rails-82bfe3bf115e7d4d6f5f5b40f8ab32a61148da67.tar.bz2 rails-82bfe3bf115e7d4d6f5f5b40f8ab32a61148da67.zip |
Add a test case for preloading through association with implicit source
If `reflection_scope.where_clause` is not empty, `through_scope` should
be joined the source association. But if the through association doesn't
have explicit `:source`, `options[:source]` will be nil and
`scope.includes_values` will also be empty. It should use
`source_reflection.name` rather than `options[:source]`.
Fixed by a26cff3c1235c61cd0135bed4ef63d7be452b458.
Fixes #11078.
Fixes #26129.
Closes #14312.
Closes #29155.
Closes #29841.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 44bf7f7d2f..9fb395853e 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -530,6 +530,14 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_equal [comments(:does_it_hurt)], assert_no_queries { author.special_post_comments } end + def test_preloading_has_many_through_with_implicit_source + authors = Author.includes(:very_special_comments).to_a + assert_no_queries do + special_comment_authors = authors.map { |author| [author.name, author.very_special_comments.size] } + assert_equal [["David", 1], ["Mary", 0], ["Bob", 0]], special_comment_authors + end + end + def test_eager_with_has_many_through_an_sti_join_model_with_conditions_on_both author = Author.all.merge!(includes: :special_nonexistent_post_comments, order: "authors.id").first assert_equal [], author.special_nonexistent_post_comments |