Parent has many Child ones, and Child belongs to Parent.
And I have something like this:
parent_id = 123
parent = Repo.get(Parent, 123)
child_id = 456 # it belongs to Parent
child = Repo.get(Child, child_id) |> Repo.delete()
# how can I now refresh parent and its "child_items"
As you can see, I’ve deleted one Child from Parent. How can I now refresh “parent” so that the amount “child_items” reflects this change? Should I retrieve it one more time from a database?
Or perhaps I should’ve deleted the child via parent? How?
What @benwilson512 means is that you have to get it after you’ve deleted the child. So add the line afterward to have parent point to the new updated Parent struct.
As you may know, everything in Elixir is immutable so there’s no such thing as reloading data like in Rails. So everywhere you store a reference to the parent will still refer to the “old” version after reloading it all these places.