Skip to content

Commit 4730d95

Browse files
authored
Fix preloader validation for multiple combinations (#4762)
1 parent 0a30f6b commit 4730d95

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎lib/ecto/repo/preloader.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ defmodule Ecto.Repo.Preloader do
392392
# If we are returning many results, we must sort by the key too
393393
query =
394394
case {card, query.combinations} do
395-
{:many, [{kind, _} | []]} ->
395+
{:many, [{kind, _} | _]} ->
396396
raise ArgumentError,
397397
"`#{kind}` queries must be wrapped inside of a subquery " <>
398398
"when preloading a `has_many` or `many_to_many` association. " <>

‎test/ecto/repo_test.exs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,6 +2138,11 @@ defmodule Ecto.RepoTest do
21382138
TestRepo.preload(%MySchema{id: 1}, children: union(query, ^query))
21392139
end
21402140

2141+
assert_raise ArgumentError, msg, fn ->
2142+
combination_query = query |> union(^query) |> union(^query)
2143+
TestRepo.preload(%MySchema{id: 1}, children: combination_query)
2144+
end
2145+
21412146
msg = ~r"`union_all` queries must be wrapped inside of a subquery"
21422147

21432148
assert_raise ArgumentError, msg, fn ->

0 commit comments

Comments
 (0)