Skip to content

Conversation

@sevenseacat
Copy link
Contributor

Continuing on from #2519, allows aggregates to reference other aggregates (with type resolution).

  • Renames the EnsureAggregateFieldIsAttributeOrCalculation verifier to just ValidateAggregateField (because EnsureAggregateFieldIsAttributeOrCalculationOrAggregate is a bit verbose) to allow aggregates
  • Updates the type resolution in Ash.Query.Aggregate.new to check aggregate types both first and recursively, ahead of the generic case
  • Makes that aggregate type resolution public so it can be reused in other places such as Ash.Domain.Info.Diagram

The tests look a bit odd because there's assertions inside a capture_io block but as I found out, defining a module inside a capture_io block in order to capture any generated warnings, doesn't make the module accessible outside the block 🫠

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies
Renamed verifier from EnsureAggregateFieldIsAttributeOrCalculation to
ValidateAggregateField and added aggregates to the list of valid field types.
Fixed case clause ordering in `Ash.Query.Aggregate.new/4` so that
`%Ash.Resource.Aggregate{}` matches before the generic pattern.

Also updated `aggregate_type/2` to recursively resolve nested aggregate types.
Updated `Ash.Resource.Info`, `Ash.Sort`, and `Ash.Domain.Info.Diagram`
modules to delegate to `Ash.Query.Aggregate.aggregate_type/2` instead
of duplicating the logic.
This stops test failures from concurrently-running tests intermittently
making this test fail
@zachdaniel zachdaniel merged commit 77cb45a into main Jan 16, 2026
45 checks passed
@zachdaniel
Copy link
Contributor

🚀 Thank you for your contribution! 🚀

@sevenseacat sevenseacat deleted the fix/aggregates-refencing-aggregates branch January 17, 2026 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants