View on GitHub
Converts the given `params` into a changeset for `model`
keeping only the set of `required` and `optional` keys.
This functions receives the `params` and cast them according
to the schema information from `model`. `params` are a map
with strings as key of potentially unsafe data.
During casting, all valid parameters will have their key name
converted to atoms and stored as a change in the changeset.
All other parameters that are not listed in `required` or
`optional` are ignored.
If casting of all fields is successful and all required fields
are present either in the model or in the given params, the
changeset is returned as valid.
## No parameters
The `params` argument can also be nil. In such cases, the
changeset is automatically marked as invalid, with an empty
changes map. This is useful to run the changeset through
all validation steps for introspection.
iex> changeset = cast(params, post, ~w(title), ~w())
iex> if changeset.valid? do
- Describe the parameter "val".