提交 82bfe3bf 编写于 作者: R Ryuta Kamizono

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 a26cff3c.

Fixes #11078.
Fixes #26129.
Closes #14312.
Closes #29155.
Closes #29841.
上级 a26cff3c
......@@ -530,6 +530,14 @@ def test_eager_with_has_many_through_an_sti_join_model
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册