fix: Correct the matching used in building a distinct expression (#196)

This commit is contained in:
Ryan 2024-01-26 15:04:54 -05:00 committed by GitHub
parent 29da61d661
commit 64e117603a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 7 deletions

View file

@ -2573,7 +2573,7 @@ defmodule AshPostgres.DataLayer do
def distinct(query, distinct_on, resource) do
case get_distinct_statement(query, distinct_on) do
{:ok, distinct_statement, query} ->
{:ok, {distinct_statement, query}} ->
%{query | distinct: distinct_statement}
|> apply_sort(query.__ash_bindings__[:sort], resource)
@ -2692,7 +2692,7 @@ defmodule AshPostgres.DataLayer do
distinct_on, {[order_by | rest_order_by], distinct_statement, params, count, query} ->
case order_by do
{^distinct_on, order} ->
{distinct_on, order} = ^distinct_on ->
{distinct_expr, params, count, query} =
distinct_on_expr(query, distinct_on, params, count)
@ -2710,11 +2710,11 @@ defmodule AshPostgres.DataLayer do
{_, result, params, _, query} ->
{:ok,
%{
distinct
| expr: distinct.expr ++ Enum.reverse(result),
params: distinct.params ++ Enum.reverse(params)
}, query}
{%{
distinct
| expr: distinct.expr ++ Enum.reverse(result),
params: distinct.params ++ Enum.reverse(params)
}, query}}
end
end
end

View file

@ -168,4 +168,13 @@ defmodule AshPostgres.DistinctTest do
%{title: "title", negative_score: -1}
] = results
end
test "distinct used on it's own" do
results =
Post
|> Ash.Query.distinct(:title)
|> Api.read!()
assert [_, _] = results
end
end