ash icon indicating copy to clipboard operation
ash copied to clipboard

Custom Aggregate Documentation

Open maennchen opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

When reading up on aggregates, it's unnecessarily hard to figure out how to define custom aggregations.

Describe the solution you'd like

The docs for Ash.Resource.DSL / aggregates.custom should point to Ash.Resource.Aggregate.CustomAggregate.

Additionally, it would be good to include an example of defining a complete aggregate in the Aggregations Doc page. For example using Postgres / string_agg.

It would also be good to go a bit more into detail about this:

Aggregates in Ash allow for retrieving summary information over groups of related data.

We should make it clear, that "related data" always means a declared relationship. As far as I understand, it can't be used on one resource only (eg. when grouping by a specific field or just on the whole table)

Describe alternatives you've considered

None.

Express the feature either with a change to resource syntax, or with a change to the resource interface

No change

Additional context

  • https://hexdocs.pm/ash/Ash.Resource.Aggregate.CustomAggregate.html
  • https://hexdocs.pm/ash/dsl-ash-resource.html#aggregates-custom
  • https://hexdocs.pm/ash/aggregates.html#aggregate-types

maennchen avatar Oct 04 '24 12:10 maennchen

Yes, it's currently always over a declared relationship. We have plans to support using a resource instead of a relationship path for much more custom aggregation.

https://github.com/ash-project/ash/issues/939

zachdaniel avatar Oct 04 '24 12:10 zachdaniel