April 2019
Beginner to intermediate
244 pages
6h 34m
English
Changesets manage the update process by breaking it into three distinct stages: casting and filtering user input, validating the input, then sending the input to the database and capturing the result. If you think of it as a pipeline, it would look something like this:
| | data |
| | |> cast_and_filter_fields |
| | |> validate_change |
| | |> validate_another_change |
| | |> send_to_database |
We’ll look at each step in detail, but here’s what the process looks like in code. The following example inserts a new Artist record, based on data supplied by the user:
| | import Ecto.Changeset |
| | |
| | params = %{name: "Gene Harris"} |
| | changeset = |
| | %Artist{} |
| | |> cast(params, ... |
Read now
Unlock full access