# Update nested struct with Ecto

**URL:** <https://forum.elixirforum.com/t/update-nested-struct-with-ecto/21128>\
**Category:** Questions\
**Tags:** ecto, changesets, phoenix, nested-associations\
**Created:** [March 25, 2019, 2:57pm UTC](https://forum.elixirforum.com/t/update-nested-struct-with-ecto/21128 "2019-03-25T14:57:56Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![jeremyjh](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jeremyjh/32/5995_2.png) [@jeremyjh](https://forum.elixirforum.com/u/jeremyjh)\
**Post date:** [March 26, 2019, 1:03pm UTC](https://forum.elixirforum.com/t/update-nested-struct-with-ecto/21128/4 "2019-03-26T13:03:25Z")

</div>

> [@helicon](#):
>
> So first time it works well, but second time it raises exception:  
> `** (RuntimeError) you are attempting to change relation :files of Asset but the :on_replace option of this relation is set to :raise.`

Yes this was what I was referring to. That means there are existing associations you have not included in your payload. After the first execution there are two files that were assigned IDs. You need to include those in your next params:

```elixir
params = %{
  files: [
    %{id: file1.id},
    %{id: file2.id},
    %{filename: "name3"},
    %{filename: "name4"} 
  ]
}

```

---

_[View the full topic](https://forum.elixirforum.com/t/update-nested-struct-with-ecto/21128)._
