Domo.Changeset (Domo v1.2.8) View Source
Module with validation functions for Echo.Changeset.
To make validate_type/*
functions work t()
type can be defined for the schema like the following:
defmodule User do
use Ecto.Schema
use Domo
import Ecto.Changeset
import Domo.Changeset
schema "users" do
field :name
field :email
field :age, :integer
end
@type t :: %__MODULE__{
name :: String.t() | nil,
email :: String.t() | nil,
age :: integer() | nil
}
def changeset(user, params \ %{}) do
user
|> cast(params, [:name, :email, :age])
|> validate_required([:name, :email])
|> validate_type()
end
end
Link to this section Summary
Functions
Validates field change values conforms to appropriate types defined within the schema's t() type.
Similar to validate_type/1, but can work with a map changeset. Takes struct module name as struct
.
Similar to validate_type/1, but validates only given fields
.
Similar to validate_type/2, but validates only given fields
.
Link to this section Functions
Validates field change values conforms to appropriate types defined within the schema's t() type.
It perform the validation only if a change value is not nil.
In case there's at least one error, the list of errors will be appended to the :errors
field of the changeset and the :valid?
flag will be set to false.
Similar to validate_type/1, but can work with a map changeset. Takes struct module name as struct
.
Examples
{%{}, %{name: :string, email: :string, age: :integer}}
|> cast(%{name: "Hello world", email: "some@address", age: 21}, [:name, :email, :age])
|> validate_type(User)
Similar to validate_type/1, but validates only given fields
.
Similar to validate_type/2, but validates only given fields
.