manage_relationship: Get changes in related records

My Invoice resource has many Items. Every item calculates its total in a change. I want to calculate the sum of those totals in the invoice but cannot find a way to read the full items, only the input. How can I do this?
argument :items, {:array, :map}, allow_nil?: false
change manage_relationship(:items, type: :create)
change fn changeset, _context ->
# How can I read the final items?
end)
argument :items, {:array, :map}, allow_nil?: false
change manage_relationship(:items, type: :create)
change fn changeset, _context ->
# How can I read the final items?
end)
2 Replies
ZachDaniel
ZachDaniel4mo ago
You'd need to add an afteraction hook and look at the items in the result
zimt28
zimt28OP4mo ago
I see. I hoped for a trick to get live updating forms but it looks like I need to solve this differently then

Did you find this page helpful?