Make Changes

Learn how to make changes while working with embedded schemas.

Now, let’s look at making some changes to our embedded records. Since the data is embedded in the parent record, it’s tempting to think that we can simply manipulate the records the same as the other fields in the schema. This is not the case.

Use changesets with embeds

We must always use changesets when working with embeds and the specialized functions Ecto provides, put_embed/4 and cast_embed/3. The child records are stored in a column in the database, but in our Elixir code, it’s more accurate to think of embeds like associations.

The put_embed/4 and cast_embed/3 keywords work just like their counterparts put_assoc/4 and cast_assoc/3, so we need to consider the ...