Ash FrameworkAF
Ash Framework3y ago
2 replies
WIGGLES

Read Action Prepare does not load aggregate

I have a resource with a count aggregate for a child resource
aggregates do
  count :response_count, :responses
end

I then have a default read action that uses prepare and build to load the aggregate
read :read do
  primary? true
  pagination offset?: true, keyset?: true, required?: false

  prepare build(aggregate: {:response_count, :count, :responses}, load: [:responses])
end

Note that I have currently loaded responses to use the length method to get a count, but whenever I attempt to access response_count it returns an Ash.NotLoaded<:aggregate> value.

Loving ASH btw, It cuts down on a lot of the boilerplate that you get with normal Phoenix contexts.
Was this page helpful?