ash-project / ash

A declarative, extensible framework for building Elixir applications.
https://www.ash-hq.org
MIT License
1.61k stars 218 forks source link

Custom Aggregate Documentation #1497

Open maennchen opened 2 weeks ago

maennchen commented 2 weeks ago

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

zachdaniel commented 2 weeks ago

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