Add embed to changeset manually

I’m trying to implement create/update actions where I manually create the changeset for the embed. This is what I currently tried, but the creation fails with an error, because the translations are missing (Ash.Error.Changes.Required)

attributes do
  attribute :translations, __MODULE__.Translations, private?: true, allow_nil?: false

create :create do
  primary? true

  change &cast_translations/2 

defp cast_translations(changeset, context) do
  translations_changeset = || __MODULE__.Translations,

  Ash.Changeset.set_argument(changeset, :translations, translations_changeset)

To set the attribute you need to use Ash.Changeset.change_attribute, not Ash.Changeset.set_argument.

1 Like

Works like a charm :heart:

Ash.Changeset.change_attribute(changeset, :translations, changeset.params)