fix nil plans bug in Tasks.update_task (#58)
This commit is contained in:
parent
cef9ea72c6
commit
404caad2ac
1 changed files with 4 additions and 2 deletions
|
@ -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 =
|
||||
|
|
Loading…
Add table
Reference in a new issue