Got an (lv) app with the following associations:
App.People.Person
belongs_to: family, App.People.Family
App.People.Family
has_many(:members, App.People.Person)
I’ve got the Person loaded, along with the associations for family and members. Imagine my family has 5 members, and I want to add the 6th.
Since I know the id of the sixth member, I was thinking I could add using put_assoc, like:
person = People.get_person_with_name(%{id: id})
existing_family = Map.get(socket.assigns.changeset.changes, :family, socket.assigns.person.family)
new_fam_members = existing_family.members ++ [person]
changeset =
socket.assigns.changeset
|> Ecto.Changeset.put_assoc(:family , Map.merge(existing_family, %{members: new_fam_members} ))
But when I IO.inspect that changeset all I get is:
#Ecto.Changeset<action: nil, changes: %{}, errors: [],
data: #App.People.Person<>, valid?: true>
No Changes!
What have I done wrong/not understood?