Casting Associations in Phoenix
If you want to cast changes on a struct's associations, you can use the changeset function cast_assoc/3
. This allows you to make changes to a parent struct and its associations at the same time.
Example
Lets say you have a struct called Artist
and an associated schema called Album
. The schema for the Album
looks something like this:
and the schema for artist looks like this:
Now, if you wanted to build a changeset for the Artist
where you can change the artist's name and the title field on an associated album: