Elixir Ecto Multi insert_all

时间:2019-04-17 02:50:56

标签: elixir phoenix-framework ecto

I'm new to using ecto.multi and I'm stuck on how to use the multi.insert_all function.

paydata_changeset = Paydata.changeset(%Paydata{}, paydata_params)

multi =
  Multi.new()
  |> Multi.insert(:paydata, paydata_changeset) # success
  |> Multi.run(:paydata_attendance, fn %{paydata: paydata} -> # success
    paydata_attendance = # How to call this data in insert_all
      Enum.map(paydata_attendance_params, fn item ->
        Map.put(item, "paydata_id", paydata.id) # add the paydata.id to paydata_attendance
      end)

    {:ok, paydata_attendance}

  end)
  |> Multi.insert_all(:insert_all, PaydataAttendance, paydata_attendance) #ERROR paydata_attendance does not exist

case Repo.transaction(multi) do
  {:ok, _} ->
    send_resp(conn, 200, "Success")

  {:error, :employees, changeset, %{}} ->
    IO.inspect(label: "ERROR HIT")
    send_resp(conn, 500, changeset)
end

I'm getting an error of paydata_attendance does not exist in my multi.insert_all.

0 个答案:

没有答案