View Source Ash.Resource.Validation behaviour (ash v2.19.3)
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 context() :: %{ optional(:actor) => Ash.Resource.record() | nil, optional(:tenant) => term(), optional(:authorize?) => boolean() | nil, optional(:tracer) => Ash.Tracer.t() | [Ash.Tracer.t()] | nil, optional(any()) => any() }
Callbacks
@callback atomic(changeset :: Ash.Changeset.t(), opts :: Keyword.t()) :: :ok | {:atomic, involved_fields :: [atom()] | :*, condition_expr :: Ash.Expr.t(), error_expr :: Ash.Expr.t()} | [ {:atomic, involved_fields :: [atom()] | :*, condition_expr :: Ash.Expr.t(), error_expr :: Ash.Expr.t()} ] | {:not_atomic, String.t()} | {:error, term()}
@callback atomic?() :: boolean()
@callback has_validate?() :: boolean()
@callback validate(changeset :: Ash.Changeset.t(), opts :: Keyword.t()) :: :ok | {:error, term()}
@callback validate( changeset :: Ash.Changeset.t(), opts :: Keyword.t(), context :: context() ) :: :ok | {:error, term()}