fix multiple hash preloads. Fixes #14994
This commit is contained in:
parent
9d835fd7f2
commit
b713e207d4
@ -112,13 +112,14 @@ def preloaders_on(association, records, scope)
|
||||
end
|
||||
|
||||
def preloaders_for_hash(association, records, scope)
|
||||
parent, child = association.to_a.first # hash should only be of length 1
|
||||
association.flat_map { |parent, child|
|
||||
loaders = preloaders_for_one parent, records, scope
|
||||
|
||||
loaders = preloaders_for_one parent, records, scope
|
||||
|
||||
recs = loaders.flat_map(&:preloaded_records).uniq
|
||||
loaders.concat Array.wrap(child).flat_map { |assoc|
|
||||
preloaders_on assoc, recs, scope
|
||||
recs = loaders.flat_map(&:preloaded_records).uniq
|
||||
loaders.concat Array.wrap(child).flat_map { |assoc|
|
||||
preloaders_on assoc, recs, scope
|
||||
}
|
||||
loaders
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -508,6 +508,13 @@ def test_find_with_preloaded_associations
|
||||
end
|
||||
end
|
||||
|
||||
def test_deep_preload
|
||||
post = Post.preload(author: :posts, comments: :post).first
|
||||
|
||||
assert_predicate post.author.association(:posts), :loaded?
|
||||
assert_predicate post.comments.first.association(:post), :loaded?
|
||||
end
|
||||
|
||||
def test_preload_applies_to_all_chained_preloaded_scopes
|
||||
assert_queries(3) do
|
||||
post = Post.with_comments.with_tags.first
|
||||
|
Loading…
Reference in New Issue
Block a user