From c9791acff8b0143a66e90105b25c831c9662ec8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20N=C3=BDvlt?= Date: Fri, 9 Aug 2024 14:37:12 +0200 Subject: [PATCH] Fix --- lib/chore_tracker/chores.ex | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/chore_tracker/chores.ex b/lib/chore_tracker/chores.ex index 3bacb2e..b98c007 100644 --- a/lib/chore_tracker/chores.ex +++ b/lib/chore_tracker/chores.ex @@ -25,10 +25,16 @@ defmodule ChoreTracker.Chores do end def update_chore(%Chore{} = chore, attrs) do + changeset = change_chore(chore, attrs) + Ecto.Multi.new() - |> Ecto.Multi.update(:chore, change_chore(chore, attrs)) + |> Ecto.Multi.update(:chore, changeset) |> Ecto.Multi.run(:update_next_assignee, fn _repo, %{chore: chore} -> - save_next_chore_assignee(chore) + if Ecto.Changeset.changed?(changeset, :assignees) do + save_next_chore_assignee(chore) + else + {:ok, chore} + end end) |> Repo.transaction() end