Ash FrameworkAF
Ash Framework3y ago
49 replies
Blibs

Aggregate first the full resource instead of some field

I have a property resource that can contain offers.

When I'm fetching the property, I want to also fetch the current offer from the actor if there is one.

Right now, I have this:

  preparations do
    prepare build(load: :offeror_current_offer)
  end

  aggregates do
    first :offeror_current_offer, :offers do
      filter expr(offeror_id == ^actor(:id) and status in [:open, :accepted, :evaluating])

      sort updated_at: :desc
    end
  end


But this will not work since the first aggregation requires me to select a field from :offers, but I want it to actually select the whole offer.

Is there some way for me to do this with aggregates?
Was this page helpful?