AntlUtilsEcto.Changeset (antl_utils_ecto v2.8.6) View Source

Set of utils for Ecto.Changeset

Link to this section Summary

Functions

A helper that transforms changeset errors into a map of messages.

A helper that convert changeset error to string (as json encoded format).

A helper that allows to apply function on a changeset only if it is valid. Always returns the changeset

Validates the given fields change are empty or unchanged.

Link to this section Functions

Specs

errors_on(Ecto.Changeset.t()) :: %{optional(atom()) => [binary()]}

A helper that transforms changeset errors into a map of messages.

Examples

iex> changeset = Ecto.Changeset.change({%{}, %{password: :string}}) |> Ecto.Changeset.cast(%{password: 123}, [:password]) iex> assert "is invalid" in AntlUtilsEcto.Changeset.errors_on(changeset).password iex> assert %{password: ["is invalid"]} = AntlUtilsEcto.Changeset.errors_on(changeset)

Link to this function

json_encode_errors(changeset)

View Source

Specs

json_encode_errors(Ecto.Changeset.t()) :: String.t()

A helper that convert changeset error to string (as json encoded format).

Link to this function

on_valid_changeset(changeset, fun)

View Source

Specs

on_valid_changeset(
  Ecto.Changeset.t(),
  (Ecto.Changeset.t() -> Ecto.Changeset.t())
) ::
  Ecto.Changeset.t()

A helper that allows to apply function on a changeset only if it is valid. Always returns the changeset

Link to this function

validate_datetime_gt(changeset, datetime_key, referal, opts \\ [])

View Source

Specs

validate_datetime_gt(
  Ecto.Changeset.t(),
  atom(),
  atom() | nil | DateTime.t(),
  keyword()
) ::
  Ecto.Changeset.t()
Link to this function

validate_datetime_gte(changeset, datetime_key, referal, opts \\ [])

View Source

Specs

validate_datetime_gte(
  Ecto.Changeset.t(),
  atom(),
  atom() | nil | DateTime.t(),
  keyword()
) ::
  Ecto.Changeset.t()
Link to this function

validate_datetime_inclusion(changeset, start_at_key, end_at_key, container_period)

View Source

Specs

validate_datetime_inclusion(
  Ecto.Changeset.t(),
  atom(),
  atom(),
  AntlUtilsElixir.DateTime.Period.t()
) :: Ecto.Changeset.t()
Link to this function

validate_datetime_inclusion(changeset, start_at_key, end_at_key, period, period_start_at_key, period_end_at_key)

View Source

Specs

validate_datetime_inclusion(
  Ecto.Changeset.t(),
  atom(),
  atom(),
  map(),
  atom(),
  atom()
) ::
  Ecto.Changeset.t()
Link to this function

validate_datetime_lt(changeset, datetime_key, referal, opts \\ [])

View Source

Specs

validate_datetime_lt(
  Ecto.Changeset.t(),
  atom(),
  atom() | nil | DateTime.t(),
  keyword()
) ::
  Ecto.Changeset.t()
Link to this function

validate_datetime_lte(changeset, datetime_key, referal, opts \\ [])

View Source

Specs

validate_datetime_lte(
  Ecto.Changeset.t(),
  atom(),
  atom() | nil | DateTime.t(),
  keyword()
) ::
  Ecto.Changeset.t()
Link to this function

validate_empty(changeset, fields, opts \\ [])

View Source

Specs

validate_empty(Ecto.Changeset.t(), any(), keyword()) :: Ecto.Changeset.t()

Validates the given fields change are empty or unchanged.

Link to this function

validate_empty_if(changeset, fields, conditional_field, expected_value, opts \\ [])

View Source

Specs

validate_empty_if(Ecto.Changeset.t(), any(), atom(), any(), keyword()) ::
  Ecto.Changeset.t()
Link to this function

validate_empty_unless(changeset, fields, conditional_field, expected_value, opts \\ [])

View Source

Specs

validate_empty_unless(Ecto.Changeset.t(), any(), atom(), any(), keyword()) ::
  Ecto.Changeset.t()
Link to this function

validate_empty_with(changeset, fields, conditional_fields, opts \\ [])

View Source

Specs

validate_empty_with(Ecto.Changeset.t(), any(), atom() | [atom()], keyword()) ::
  Ecto.Changeset.t()
Link to this function

validate_empty_with_all(changeset, fields, conditional_fields, opts \\ [])

View Source

Specs

validate_empty_with_all(Ecto.Changeset.t(), any(), [atom()], keyword()) ::
  Ecto.Changeset.t()
Link to this function

validate_empty_without(changeset, fields, conditional_fields, opts \\ [])

View Source

Specs

validate_empty_without(Ecto.Changeset.t(), any(), atom() | [atom()], keyword()) ::
  Ecto.Changeset.t()
Link to this function

validate_empty_without_all(changeset, fields, conditional_fields, opts \\ [])

View Source

Specs

validate_empty_without_all(Ecto.Changeset.t(), any(), [atom()], keyword()) ::
  Ecto.Changeset.t()
Link to this function

validate_required_any(changeset, fields, opts \\ [])

View Source

Specs

validate_required_any(Ecto.Changeset.t(), list(), keyword()) ::
  Ecto.Changeset.t()
Link to this function

validate_required_any_if(changeset, fields, conditional_field, expected_value, opts \\ [])

View Source

Specs

validate_required_any_if(Ecto.Changeset.t(), any(), atom(), any(), keyword()) ::
  Ecto.Changeset.t()
Link to this function

validate_required_any_unless(changeset, fields, conditional_field, expected_value, opts \\ [])

View Source

Specs

validate_required_any_unless(
  Ecto.Changeset.t(),
  any(),
  atom(),
  any(),
  keyword()
) ::
  Ecto.Changeset.t()
Link to this function

validate_required_if(changeset, fields, conditional_field, expected_value, opts \\ [])

View Source

Specs

validate_required_if(Ecto.Changeset.t(), any(), atom(), any(), keyword()) ::
  Ecto.Changeset.t()
Link to this function

validate_required_if_any(changeset, fields, conditional_field, expected_values, opts \\ [])

View Source

Specs

validate_required_if_any(Ecto.Changeset.t(), any(), atom(), list(), keyword()) ::
  Ecto.Changeset.t()
Link to this function

validate_required_one_exclusive(changeset, fields, opts \\ [])

View Source

Specs

validate_required_one_exclusive(
  Ecto.Changeset.t(),
  [any()],
  keyword()
) :: Ecto.Changeset.t()
Link to this function

validate_required_unless(changeset, fields, conditional_field, expected_value, opts \\ [])

View Source

Specs

validate_required_unless(Ecto.Changeset.t(), any(), atom(), any(), keyword()) ::
  Ecto.Changeset.t()
Link to this function

validate_required_with(changeset, fields, conditional_fields, opts \\ [])

View Source

Specs

validate_required_with(Ecto.Changeset.t(), any(), atom() | [atom()], keyword()) ::
  Ecto.Changeset.t()
Link to this function

validate_required_with_all(changeset, fields, conditional_fields, opts \\ [])

View Source

Specs

validate_required_with_all(Ecto.Changeset.t(), any(), [atom()], keyword()) ::
  Ecto.Changeset.t()
Link to this function

validate_required_without(changeset, fields, conditional_fields, opts \\ [])

View Source

Specs

validate_required_without(
  Ecto.Changeset.t(),
  any(),
  atom() | [atom()],
  keyword()
) ::
  Ecto.Changeset.t()
Link to this function

validate_required_without_all(changeset, fields, conditional_fields, opts \\ [])

View Source

Specs

validate_required_without_all(Ecto.Changeset.t(), any(), [atom()], keyword()) ::
  Ecto.Changeset.t()