Ecto.Multi.insert_all
You're seeing just the function
insert_all
, go back to Ecto.Multi module for more information.
Link to this function
insert_all(multi, name, schema_or_source, entries_or_fun, opts \\ [])
View SourceSpecs
insert_all( t(), name(), schema_or_source(), [map() | Keyword.t()] | fun([map() | Keyword.t()]), Keyword.t() ) :: t()
Adds an insert_all operation to the multi.
Accepts the same arguments and options as Ecto.Repo.insert_all/3
does.
Example
posts = [%{title: "My first post"}, %{title: "My second post"}]
Ecto.Multi.new()
|> Ecto.Multi.insert_all(:insert_all, Post, posts)
|> MyApp.Repo.transaction()
Ecto.Multi.new()
|> Ecto.Multi.run(:post, fn repo, _changes ->
case repo.get(Post, 1) do
nil -> {:error, :not_found}
post -> {:ok, post}
end
end)
|> Ecto.Multi.insert_all(:insert_all, Comment, fn %{post: post} ->
# Others validations
entries
|> Enum.map(fn comment ->
Map.put(comment, :post_id, post.id)
end)
end)
|> MyApp.Repo.transaction()