mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 05:23:18 +12:00
fix: subquery aggregates when a distinct is being added
This commit is contained in:
parent
903b1dd2e7
commit
d417361012
2 changed files with 21 additions and 5 deletions
|
@ -668,11 +668,21 @@ defmodule AshPostgres.DataLayer do
|
||||||
@impl true
|
@impl true
|
||||||
def run_aggregate_query(query, aggregates, resource) do
|
def run_aggregate_query(query, aggregates, resource) do
|
||||||
query =
|
query =
|
||||||
query
|
if query.distinct do
|
||||||
|> Ecto.Query.exclude(:select)
|
query =
|
||||||
|> Ecto.Query.exclude(:order_by)
|
query
|
||||||
|> Map.put(:windows, [])
|
|> Ecto.Query.exclude(:select)
|
||||||
|> Ecto.Query.select(%{})
|
|> Ecto.Query.exclude(:order_by)
|
||||||
|
|> Map.put(:windows, [])
|
||||||
|
|
||||||
|
from(row in subquery(query), as: ^0, select: %{})
|
||||||
|
else
|
||||||
|
query
|
||||||
|
|> Ecto.Query.exclude(:select)
|
||||||
|
|> Ecto.Query.exclude(:order_by)
|
||||||
|
|> Map.put(:windows, [])
|
||||||
|
|> Ecto.Query.select(%{})
|
||||||
|
end
|
||||||
|
|
||||||
query =
|
query =
|
||||||
Enum.reduce(
|
Enum.reduce(
|
||||||
|
|
|
@ -953,6 +953,12 @@ defmodule AshPostgres.AggregateTest do
|
||||||
|> Api.read_one!()
|
|> Api.read_one!()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "a count with a filter that references a to many relationship can be aggregated at the query level" do
|
||||||
|
Post
|
||||||
|
|> Ash.Query.filter(comments.likes > 10)
|
||||||
|
|> Api.count!()
|
||||||
|
end
|
||||||
|
|
||||||
test "a count with a filter that references a relationship combined with another" do
|
test "a count with a filter that references a relationship combined with another" do
|
||||||
post =
|
post =
|
||||||
Post
|
Post
|
||||||
|
|
Loading…
Reference in a new issue