Model Change with Changesets

Let's learn how forms and changesets work.

We'll cover the following

Ecto changesets

Changesets are policies for changing data, and they fulfill these roles:

  • Changesets cast unstructured user data into a known, structured form to ensure data safety. The most common structure is an Ecto database schema.

  • Changesets capture differences between safe, consistent data and a proposed change, allowing efficiency.

  • Changesets validate data using known consistent rules, ensuring data consistency.

  • Changesets provide a contract for communicating error states and valid states, ensuring a common interface for change.

We can see changesets in action in the Product.changeset/2 function in pento/lib/pento/catalog/product.ex:

Get hands-on with 1200+ tech skills courses.