Awlexus

Awlexus

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
end

create :create do
  primary? true

  change &cast_translations/2 
end

defp cast_translations(changeset, context) do
  translations_changeset =
    Ash.Changeset.new(
      changeset.data.translations || __MODULE__.Translations,
      changeset.params
    )

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

Marked As Solved

zachdaniel

zachdaniel

Creator of Ash

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

Last Post!

Awlexus

Awlexus

Works like a charm :heart:

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

Where Next?

Popular in Questions Top

New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

We're in Beta

About us Mission Statement