From 404caad2ac1ec7980a9abf120d9016f15f2738b7 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 21 Nov 2020 18:28:25 -0700 Subject: [PATCH] fix nil plans bug in Tasks.update_task (#58) --- lib/planner/tasks.ex | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/planner/tasks.ex b/lib/planner/tasks.ex index 23919e8..a92dd6a 100644 --- a/lib/planner/tasks.ex +++ b/lib/planner/tasks.ex @@ -74,14 +74,16 @@ defmodule Planner.Tasks do end def update_task(%Task{} = task, attrs) do - new_plan_details_changesets = Enum.map(attrs["plans"], fn(plan_id) -> + plans = Map.get(attrs, "plans", []) + + new_plan_details_changesets = Enum.map(plans, fn(plan_id) -> PlanDetail.changeset(%PlanDetail{}, %{"task_id" => task.id, "plan_id" => plan_id}) end) deleted_plan_details = Ecto.Query.from( pd in PlanDetail, - where: pd.task_id == ^task.id and pd.plan_id not in ^attrs["plans"] + where: pd.task_id == ^task.id and pd.plan_id not in ^plans ) multi =