View Source Ash.Resource.Validation behaviour (ash v2.14.17)

Represents a validation in Ash.

See Ash.Resource.Validation.Builtins for a list of builtin validations.

To write your own validation, define a module that implements the init/1 callback to validate options at compile time, and validate/2 callback to do the validation.

Then, in a resource, you can say:

validations do
  validate {MyValidation, [foo: :bar]}
end

Summary

Types

@type path() :: [atom() | integer()]
@type ref() :: {module(), Keyword.t()} | module()
@type t() :: %Ash.Resource.Validation{
  before_action?: term(),
  description: String.t() | nil,
  message: term(),
  module: atom(),
  on: [atom()],
  only_when_valid?: boolean(),
  opts: [atom()],
  validation: {atom(), [atom()]},
  where: [{atom(), [atom()]}]
}

Callbacks

@callback atomic?(Keyword.t()) :: boolean()
@callback describe(Keyword.t()) :: String.t() | [message: String.t(), vars: Keyword.t()]
@callback init(Keyword.t()) :: {:ok, Keyword.t()} | {:error, String.t()}
@callback validate(Ash.Changeset.t(), Keyword.t()) :: :ok | {:error, term()}

Functions