Xema.Builder.field
You're seeing just the function
field
, go back to Xema.Builder module for more information.
Specs
Specifies a field. This function will be used inside xema/0
.
Arguments:
name
: the name of the field.type
: the type of the field. Thetype
can also be astruct
or another schema.opts
: the rules for the field.
Examples
iex> defmodule User do
...> use Xema
...>
...> xema do
...> field :name, :string, min_length: 1
...> end
...> end
...>
iex> %{"name" => "Tim"} |> User.cast!() |> Map.from_struct()
%{name: "Tim"}
For more examples see "Examples: Struct".