diff --git a/lib/ash/filter/filter.ex b/lib/ash/filter/filter.ex index 0a61c2b3..ef6c4008 100644 --- a/lib/ash/filter/filter.ex +++ b/lib/ash/filter/filter.ex @@ -2363,7 +2363,8 @@ defmodule Ash.Filter do filterable?: aggregate.filterable?, type: aggregate.type, constraints: aggregate.constraints, - implementation: aggregate.implementation + implementation: aggregate.implementation, + uniq?: aggregate.uniq? ) do case parse_predicates(nested_statement, query_aggregate, context) do {:ok, nested_statement} -> @@ -2892,7 +2893,8 @@ defmodule Ash.Filter do filterable?: aggregate.filterable?, type: aggregate.type, constraints: aggregate.constraints, - implementation: aggregate.implementation + implementation: aggregate.implementation, + uniq?: aggregate.uniq? ) do {:ok, %{ref | attribute: query_aggregate, resource: related}} else diff --git a/lib/ash/query/query.ex b/lib/ash/query/query.ex index 5826064b..aa87096b 100644 --- a/lib/ash/query/query.ex +++ b/lib/ash/query/query.ex @@ -936,7 +936,8 @@ defmodule Ash.Query do filterable?: aggregate.filterable?, type: aggregate.type, constraints: aggregate.constraints, - implementation: aggregate.implementation + implementation: aggregate.implementation, + uniq?: aggregate.uniq? ) do query_aggregate = %{query_aggregate | load: field} new_aggregates = Map.put(query.aggregates, aggregate.name, query_aggregate) @@ -1492,7 +1493,8 @@ defmodule Ash.Query do Keyword.get(opts, :filterable?, true), opts[:type], Keyword.get(opts, :constraints, []), - opts[:implementation] + opts[:implementation], + opts[:uniq?] ) end @@ -1511,6 +1513,7 @@ defmodule Ash.Query do atom | list(atom), Ash.Query.t() | Keyword.t() | nil ) :: t() + @deprecated "use `aggregate/5` instead" def aggregate( query, name, @@ -1521,7 +1524,8 @@ defmodule Ash.Query do filterable? \\ true, type \\ nil, constraints \\ [], - implementation \\ nil + implementation \\ nil, + uniq? \\ false ) do {field, agg_query} = case agg_query do @@ -1568,7 +1572,8 @@ defmodule Ash.Query do filterable?: filterable?, type: type, constraints: constraints, - implementation: implementation + implementation: implementation, + uniq?: uniq? ) do {:ok, aggregate} -> new_aggregates = Map.put(query.aggregates, aggregate.name, aggregate) diff --git a/lib/ash/resource/aggregate/aggregate.ex b/lib/ash/resource/aggregate/aggregate.ex index 2c4a71f3..fc366db6 100644 --- a/lib/ash/resource/aggregate/aggregate.ex +++ b/lib/ash/resource/aggregate/aggregate.ex @@ -14,6 +14,7 @@ defmodule Ash.Resource.Aggregate do :field, :sort, :default, + :uniq?, filterable?: true ]