Casting and Filtering

The first step is to take the raw input data that you want to apply to the database and generate an Ecto.Changeset struct. We call this “casting and filtering” because we perform any needed type casting operations (for example, turning a string into an integer), and we filter out any values we don’t want to use. You can do this two different ways, depending on where your data is coming from. We’ll look at both in the following sections.

Creating Changesets Using Internal Data

If the data is internal to the application (that is, you’re generating the data yourself in your application code), you can create a changeset using the Ecto.Changeset.change function. Here’s how you would create a changeset that inserts a new Artist ...

Get Programming Ecto now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.