提交 953543a6 编写于 作者: R Ryuta Kamizono

Merge pull request #37434 from giraffate/fix_eager_loading_with_limit_and_join_has_many

Fix eager load for no :has_many with limit and joins for :has_many
上级 7b6e25c9
......@@ -376,7 +376,8 @@ def apply_join_dependency(eager_loading: group_values.empty?)
)
relation = except(:includes, :eager_load, :preload).joins!(join_dependency)
if eager_loading && !using_limitable_reflections?(join_dependency.reflections)
reflections = join_dependency.reflections + joins_values.map { |joins_value| reflect_on_association(joins_value) }.reject(&:blank?)
if eager_loading && !using_limitable_reflections?(reflections)
if has_limit_or_offset?
limited_ids = limited_ids_for(relation)
limited_ids.empty? ? relation.none! : relation.where!(primary_key => limited_ids)
......
......@@ -1329,6 +1329,12 @@ def test_with_limiting_with_custom_select
assert_equal [0, 1, 1], posts.map(&:author_id).sort
end
def test_eager_load_for_no_has_many_with_limit_and_joins_for_has_many
relation = Post.eager_load(:author).joins(:comments)
assert_equal 5, relation.to_a.size
assert_equal relation.limit(5).to_a.size, relation.to_a.size
end
def test_find_one_message_on_primary_key
e = assert_raises(ActiveRecord::RecordNotFound) do
Car.find(0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册