Supports callback in Ash Validations
Is the
Copied and pasted this email validation example from the Ash docs https://hexdocs.pm/ash/validations.html#supporting-queries-in-custom-validations
but I'm getting this error:
supports/1supports/1 callback for the validation behaviour no longer available in Ash?Copied and pasted this email validation example from the Ash docs https://hexdocs.pm/ash/validations.html#supporting-queries-in-custom-validations
defmodule MyApp.Validations.Email do
use Ash.Resource.Validation
@impl true
def init(opts) do
{:ok, opts}
end
@impl true
def supports(_opts), do: [Ash.Changeset, Ash.Query]
@impl true
def validate(subject, opts, _context) do
value = get_value(subject, opts[:attribute])
if is_nil(value) || valid_email?(value) do
:ok
else
{:error, field: opts[:attribute], message: "must be a valid email"}
end
end
defp get_value(%Ash.Changeset{} = changeset, attribute) do
Ash.Changeset.get_argument_or_attribute(changeset, attribute)
end
defp get_value(%Ash.Query{} = query, attribute) do
Ash.Query.get_argument(query, attribute)
end
defp valid_email?(email) do
String.match?(email, ~r/^[^\s]+@[^\s]+\.[^\s]+$/)
end
enddefmodule MyApp.Validations.Email do
use Ash.Resource.Validation
@impl true
def init(opts) do
{:ok, opts}
end
@impl true
def supports(_opts), do: [Ash.Changeset, Ash.Query]
@impl true
def validate(subject, opts, _context) do
value = get_value(subject, opts[:attribute])
if is_nil(value) || valid_email?(value) do
:ok
else
{:error, field: opts[:attribute], message: "must be a valid email"}
end
end
defp get_value(%Ash.Changeset{} = changeset, attribute) do
Ash.Changeset.get_argument_or_attribute(changeset, attribute)
end
defp get_value(%Ash.Query{} = query, attribute) do
Ash.Query.get_argument(query, attribute)
end
defp valid_email?(email) do
String.match?(email, ~r/^[^\s]+@[^\s]+\.[^\s]+$/)
end
endbut I'm getting this error:
got "@impl true" for function supports/1 but no behaviour specifies such callback. The known callbacks are:
* Ash.Resource.Validation.atomic/3 (function)
* Ash.Resource.Validation.atomic?/0 (function)
* Ash.Resource.Validation.describe/1 (function)
* Ash.Resource.Validation.has_validate?/0 (function)
* Ash.Resource.Validation.init/1 (function)
* Ash.Resource.Validation.validate/3 (function)
Elixirgot "@impl true" for function supports/1 but no behaviour specifies such callback. The known callbacks are:
* Ash.Resource.Validation.atomic/3 (function)
* Ash.Resource.Validation.atomic?/0 (function)
* Ash.Resource.Validation.describe/1 (function)
* Ash.Resource.Validation.has_validate?/0 (function)
* Ash.Resource.Validation.init/1 (function)
* Ash.Resource.Validation.validate/3 (function)
Elixir