Ash.Resource.Validation behaviour (ash v3.5.43)
View SourceRepresents 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/3
callback to do the validation.
Then, in a resource, you can say:
validations do
validate {MyValidation, [foo: :bar]}
end
Summary
Types
@type t() :: %Ash.Resource.Validation{ __spark_metadata__: Spark.Dsl.Entity.spark_meta(), always_atomic?: term(), 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( changeset_query_or_input :: Ash.Changeset.t() | Ash.ActionInput.t(), opts :: Keyword.t(), context :: Ash.Resource.Validation.Context.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 supports(opts :: Keyword.t()) :: [Ash.Changeset | Ash.Query | Ash.ActionInput]
@callback validate( changeset_query_or_input :: Ash.Changeset.t() | Ash.ActionInput.t(), opts :: Keyword.t(), context :: Ash.Resource.Validation.Context.t() ) :: :ok | {:error, term()}