How to add a change to an association's changeset as a subsequent call to put_assoc/4?

foo
|> Repo.preload(:bar)
|> Foo.changeset(attrs)
|> Changeset.put_change(:a_field_name, "a value")
|> Changeset.put_assoc(:bar, %{another_field_name: "another value"})

If I want to add another change into foo’s changeset, I can call put_change/3 again.
But how should I add other changes into the association’s changeset (bar’s changeset)?

Of course I can simply add another entry into the map passed to put_assoc/4 above, but the question is, how can I do that as a separate/subsequent call (e.g. the changeset above is passed to another function that wants to add changes to the association’s changeset).

Thank you for any help

this should work

put_assoc(:bar, %{foo.bar | another_field_name: "another value" })

edit: Actually you want put_assoc chain and this doesn’t solve that problem. Also put_assoc works with full data.

Something like this should work:

bar_changeset =
  Ecto.Changeset.get_change(changeset, :bar)
  |> Ecto.Changeset.put_change(:add_this_field_to_bar_changeset, "whatever")

changeset =
  Ecto.Changeset.put_assoc(changeset, :bar, bar_changeset)

Any guidance on how to do this when the association is a list? (foo has_many bar’s?)