Skip to content

Commit 2e66ee8

Browse files
Fix join count conflicts (#4592)
1 parent 29c5804 commit 2e66ee8

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/ecto/query/builder/join.ex

+2-4
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,9 @@ defmodule Ecto.Query.Builder.Join do
165165
if is_nil(count_bind) do
166166
query =
167167
quote do
168-
query = Ecto.Queryable.to_query(unquote(query))
169-
join_count = Builder.count_binds(query)
170-
query
168+
Ecto.Queryable.to_query(unquote(query))
171169
end
172-
{quote(do: join_count), query}
170+
{quote(do: Builder.count_binds(unquote(query))), query}
173171
else
174172
{count_bind, query}
175173
end

test/ecto/query/builder/join_test.exs

+13
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,17 @@ defmodule Ecto.Query.Builder.JoinTest do
202202
end, [], __ENV__)
203203
end
204204
end
205+
206+
test "join count is incremented correctly for runtime sources" do
207+
users_table = "users"
208+
source_query = fn -> from p in "posts", join: c in "comments", on: true end
209+
210+
q =
211+
from s in source_query.(),
212+
join: j in subquery(from u in users_table, join: p in "profiles", on: true, select: u.id),
213+
on: true,
214+
select: {s.id, j.id}
215+
216+
assert {:{}, _, [_, {{:., [], [{:&, [], [2]}, :id]}, [], []}]} = q.select.expr
217+
end
205218
end

0 commit comments

Comments
 (0)