In short the answer is you create them similar to how you would a usual assoc. In ecto there are associations (think has_one, has_many) and there are embeds (think embeds_one, embeds_many). Each of those has their own function for creating a changeset; cast_assoc and cast_embed. In your case you probably want a cast_embed
Just to post the example from the documentation so that it’s immediately clear how to do this (I still had to spend some time finding the answer even after reading through this thread):
def changeset(schema, params) do
schema
|> cast(params, [:name])
|> cast_embed(:child, with: &child_changeset/2)
end
defp child_changeset(schema, params) do
schema
|> cast(params, [:name, :age])
end
In short, you’ll need to call the cast_embed function and provide the changeset function defined for the embedded schema under the with: key.