Ash FrameworkAF
Ash Framework3y ago
27 replies
frankdugan3

Calculation with arguments used in another calculation for sorting

I have a calculation that uses a postgres function to return a json object:

calculate :total_hours_report,
          Hsm.Ash.Payroll.TotalHoursReport,
          expr(
            type(
              fragment(
                "get_attendance_summary(?, ?, ?)",
                id,
                ^arg(:start_date),
                ^arg(:end_date)
              ),
              ^Hsm.Ash.Payroll.TotalHoursReport
            )
          ) do
  private? true
  argument :start_date, :date, allow_nil?: false
  argument :end_date, :date, allow_nil?: false
end

It produces a number of fields like total_hours etc that I'd like to sort on.

I know I need to extract the field with another calculation and sort on that, but I'm getting a little hung up on how to handle calling a calculation with args inside another calculation with args. It's also a fairly expensive operation, so if possible I'd like to somehow tell it to use the already-loaded calculation and not require the arguments at all.

Any pointers? :thinkies:
Was this page helpful?