Ecto.Changeset.cast_embed
You're seeing just the function
cast_embed
, go back to Ecto.Changeset module for more information.
Casts the given embed with the changeset parameters.
The parameters for the given embed will be retrieved
from changeset.params
. Those parameters are expected to be
a map with attributes, similar to the ones passed to cast/4
.
Once parameters are retrieved, cast_embed/3
will match those
parameters with the embeds already in the changeset record.
See cast_assoc/3
for an example of working with casts and
associations which would also apply for embeds.
The changeset must have been previously cast
using
cast/4
before this function is invoked.
Options
:required
- if the embed is a required field:required_message
- the message on failure, defaults to "can't be blank":invalid_message
- the message on failure, defaults to "is invalid":force_update_on_change
- force the parent record to be updated in the repository if there is a change, defaults totrue
:with
- the function to build the changeset from params. Defaults to thechangeset/2
function of the embedded module. It can be changed by passing an anonymous function or an MFA tuple. If using an MFA, the default changeset and parameters arguments will be prepended to the given args. For example, usingwith: {Author, :special_changeset, ["hello"]}
will be invoked asAuthor.special_changeset(changeset, params, "hello")