mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-19 21:13:19 +12:00
fix: Correct the matching used in building a distinct expression (#196)
This commit is contained in:
parent
29da61d661
commit
64e117603a
2 changed files with 16 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue