Phoenix form for a list of records using changesets

Hi folks. I’m trying to make a LiveView page which lets you edit a list of items. However I wasn’t sure what the best way to do that was in terms of how to handle the changesets, as there is no natural parent record in my case. A couple of options I’ve considered:

  • Use an embedded schema that just has a has_many relationship to Item, then use inputs_for to iterate over the items to make the form. Mostly works well, except when doing Repo.insert(item_container) I then get an error because you can’t insert a struct for an embedded schema. Feel there is probably a way around this but not sure the best approach
  • Use a map or a list of changesets with a form for each - doesn’t feel ideal!

Thoughts appreciated!

Hey I was running into the same problem and found Ecto had a embeds_many feature Ecto.Schema — Ecto v3.9.1 hope it helps!