fix: only accept kw list in aggregate/5

This commit is contained in:
Zach Daniel 2020-12-28 19:33:01 -05:00
parent 42deba22f0
commit 9efe0355e8

View file

@ -553,22 +553,20 @@ defmodule Ash.Query do
atom(),
Ash.aggregate_kind(),
atom | list(atom),
Ash.query() | nil
Keyword.t() | nil
) :: t()
def aggregate(query, name, type, relationship, agg_query \\ nil) do
{field, agg_query} = Keyword.pop(agg_query || [], :field)
query = to_query(query)
relationship = List.wrap(relationship)
if Ash.Resource.data_layer_can?(query.resource, {:aggregate, type}) do
agg_query =
case agg_query do
nil ->
[] ->
nil
%__MODULE__{} = agg_query ->
agg_query
options when is_list(options) ->
build(Ash.Resource.related(query.resource, relationship), options)
end