Skip to content

Commit ee9e011

Browse files
authored
Merge pull request #174 from antonsatin/fix-custom-distinct
Fix for custom `distinct` handling in laterals
2 parents dff6fd3 + 9d9d3eb commit ee9e011

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/dataloader/ecto.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,8 @@ if Code.ensure_loaded?(Ecto) do
925925
build_preload_lateral_query(rest, join_query, :join_last)
926926
end
927927

928-
defp maybe_distinct(%Ecto.Query{distinct: dist} = query, _) when dist, do: query
928+
defp maybe_distinct(%Ecto.Query{distinct: distinct} = query, _) when not is_nil(distinct),
929+
do: query
929930

930931
defp maybe_distinct(query, [%Ecto.Association.Has{}, %Ecto.Association.BelongsTo{} | _]),
931932
do: distinct(query, true)

test/dataloader/ecto/limit_query_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ defmodule Dataloader.LimitQueryTest do
3636
|> preload(likes: :user)
3737
end
3838

39-
defp query(schema, %{limit: limit, order_by: order_by}, test_pid) do
39+
defp query(schema, %{limit: limit, distinct: true, order_by: order_by}, test_pid) do
4040
send(test_pid, :querying)
4141

4242
schema
4343
|> order_by(^order_by)
4444
|> limit(^limit)
45+
|> distinct(true)
4546
end
4647

47-
defp query(schema, %{limit: limit, distinct: true, order_by: order_by}, test_pid) do
48+
defp query(schema, %{limit: limit, order_by: order_by}, test_pid) do
4849
send(test_pid, :querying)
4950

5051
schema
5152
|> order_by(^order_by)
5253
|> limit(^limit)
53-
|> distinct(true)
5454
end
5555

5656
test "Query limit does not apply globally", %{loader: loader} do

0 commit comments

Comments
 (0)