View Source Ash.Calculation behaviour (ash v2.11.8)

The behaviour for a calculation module

Use select/2 to apply a select statement when the calculation is loaded. This does not apply in the case that you are loading on existing resources using MyApi.load. It also doesn't apply when the calculation is used in a filter or sort, because it is not necessary to select fields to power filters done in the data layer.

Link to this section Summary

Link to this section Types

@type context() :: %{
  :actor => term() | nil,
  :tenant => String.t() | nil,
  :authorize? => boolean() | nil,
  :tracer => module() | nil,
  optional(atom()) => any()
}
@type opts() :: Keyword.t()

Link to this section Callbacks

Link to this callback

calculate(list, opts, context)

View Source (optional)
@callback calculate([Ash.Resource.record()], opts(), context()) ::
  {:ok, [term()]} | [term()] | {:error, term()} | :unknown
@callback describe(opts()) :: String.t()
Link to this callback

expression(opts, context)

View Source (optional)
@callback expression(opts(), context()) :: any()
@callback init(opts()) :: {:ok, opts()} | {:error, term()}
@callback load(Ash.Query.t(), opts(), context()) :: atom() | [atom()] | Keyword.t()
Link to this callback

select(t, opts, context)

View Source
@callback select(Ash.Query.t(), opts(), context()) :: [atom()]