#
View Source Ash.Calculation behaviour (ash v2.14.2)

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

## Types

context()
opts()

## Callbacks

calculate(list, opts, context)
describe(opts)
expression(opts, context)
init(opts)
load(t, opts, context)
select(t, opts, context)

# Link to this section Types

Link to this type

# context()

View Source

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

Link to this type

# opts()

View Source

    @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

Link to this callback

# describe(opts)

View Source

    @callback describe(opts()) :: String.t()

Link to this callback

# expression(opts, context)

View Source (optional)

    @callback expression(opts(), context()) :: any()

Link to this callback

# init(opts)

View Source

    @callback init(opts()) :: {:ok, opts()} | {:error, term()}

Link to this callback

# load(t, opts, context)

View Source

    @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()]