How to retrieve id from previous inserted table key by Ecto Multi

I’m sorry for my multi post with SOF.
I would like to retrieve id from previous inserted table primary key by Ecto Multi.

At first, I insert to A main table. then B details table needs A.id. I tried following code.

Multi.new()
  |> Multi.insert(:insert, main)     # insert 1 recode
  |> Multi.insert_all(:insert_all, B, details)    # insert 3 recodes with main id
  |> Repo.transaction()

However I have no idea how to retrieve A.id for insert table B. What I should do for it?

You can use the :returning parameter to do that…

Sorry. I don’t look into this.