Updating array embeds
https://ash-hq.org/docs/guides/ash/latest/topics/embedded-resources says this for Array embeds
Ecto has an api to update array embeds while keeping existing
id
s. Is there a way to do the same using Ash?9 Replies
When you add a primary key to the embed, it should behave that way: https://ash-hq.org/docs/guides/ash/latest/topics/embedded-resources#array-embeds-with-primary-keys
that is just the behavior that it has when you don't add a primary key to the embed
I see. Should the code look like this? The example code seems to show only
Ash.Changeset.new
.
I should remove that sample code then, because generally speaking
Ash.Changeset.new()
shouldn't be used unless you explicitly need to make some modifications to the changeset before the action is called.
but yes it would look roughly like that, and you'd have %{embedded_list: [%{id: id1}, %{id: id2}]}
keep in mind that with the current logic it has you still need to include all items in the list.Okay. Let me try. thank you!
Also keep in mind: if you supply a list of structs, the structs just become the new value, no matching by id is performed. So what you can do if you want some custom update
Thats just one example, but You can accept arbitrary input in actions, and use that input to make your own changes to the list of structs, and then set the new value.
Thanks. I tried this. There is no error but it's not being recorded to the DB.
you're not returning the changeset that you're changing the attribute on
the
IO.inspect(changeset)
is causing it to return the original changesetOops... thanks 🙂