ex_commons v0.1.3 ExCommons.Ecto.Changeset

Helpers for Ecto changeset

Link to this section Summary

Functions

Gets changes as a simple map from a changeset

Examples

Gets changes errors as a map.

Examples

Link to this section Functions

Link to this function get_changes(changeset_list)

Gets changes as a simple map from a changeset

Examples

iex> ExCommons.Ecto.Changeset.get_changes(%{changes: %{some: :change}, valid?: true}) %{some: :change}

iex> changeset = %{changes: %{some: :change, other: %{changes: %{embed_change: true}, valid?: true}}, valid?: true} iex> ExCommons.Ecto.Changeset.get_changes(changeset) %{some: :change, other: %{embed_change: true}}

iex> changeset = %{changes: %{root: %{changes: %{one: %{changes: %{two: true}, valid?: true}}, valid?: true}}, valid?: true} iex> ExCommons.Ecto.Changeset.get_changes(changeset) %{root: %{one: %{two: true}}}

iex> changeset = %{changes: %{root: [%{changes: %{one: %{changes: %{two: true}, valid?: true}}, valid?: true}]}, valid?: true} iex> ExCommons.Ecto.Changeset.get_changes(changeset) %{root: [%{one: %{two: true}}]}

Link to this function get_errors(changeset_list)

Gets changes errors as a map.

Examples

iex> ExCommons.Ecto.Changeset.get_errors(%{changes: %{some: :change}, valid?: true}) %{}

iex> changeset = %{changes: %{other: %{changes: %{embed_change: true}, valid?: true}}, valid?: false, errors: [must: {“can’t be blank”, [validation: :required]}]} iex> ExCommons.Ecto.Changeset.get_errors(changeset) %{must: {“can’t be blank”, [validation: :required]}}

iex> changeset = %{changes: %{other: %{changes: %{embed_change: true}, errors: [must: {“can’t be blank”, [validation: :required]}], valid?: false}}, valid?: false, errors: []} iex> ExCommons.Ecto.Changeset.get_errors(changeset) %{other: %{must: {“can’t be blank”, [validation: :required]}}}

iex> changeset = %{changes: %{other: [%{changes: %{embed_change: true}, errors: [must: {“can’t be blank”, [validation: :required]}], valid?: false}]}, valid?: false, errors: []} iex> ExCommons.Ecto.Changeset.get_errors(changeset) %{other: [%{must: {“can’t be blank”, [validation: :required]}}]}