Introduction to Changesets

Learn about changesets.

Introduction

We have seen how schemas provide a quick method for inserting new records into the database, even with associated records. A database is only as good as the quality of the data it contains, so we need to be careful about the modifications we make to that data. The Ecto.Changeset module provides a rich data structure and many functions that help us make changes safely and securely.

What we’ll learn

This chapter will explore the world of changesets.

  • We’ll start by taking a high-level look at the process of making a change.

  • We’ll then look at each step of the process in detail, casting and filtering user-provided data, validating the data, and capturing errors.

  • Finally, we will look at how changesets help us with the often tricky process of working with associations and embeds.

Changesets

Changesets manage the update process by breaking it into three distinct stages:

  • Cast and filter user input
  • Validate the input
  • Send the input to the database and capture the result

If we think of it as a pipeline, it’ll look something like this:

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy