Ecto.Multi.merge
merge
, go back to Ecto.Multi module for more information.
Specs
Merges a multi returned dynamically by an anonymous function.
This function is useful when the multi to be merged requires information from the original multi. Hence the second argument is an anonymous function that receives the multi changes so far. The anonymous function must return another multi.
If you would prefer to simply merge two multis together, see append/2
or
prepend/2
.
Duplicated operations are not allowed.
Example
multi =
Ecto.Multi.new()
|> Ecto.Multi.insert(:post, %Post{title: "first"})
multi
|> Ecto.Multi.merge(fn %{post: post} ->
Ecto.Multi.new()
|> Ecto.Multi.insert(:comment, Ecto.build_assoc(post, :comments))
end)
|> MyApp.Repo.transaction()
Specs
Merges a multi returned dynamically by calling module
and function
with args
.
Similar to merge/2
, but allows to pass module name, function and arguments.
The function should return an Ecto.Multi
, and receives changes so far
as the first argument (prepended to those passed in the call to the function).
Duplicated operations are not allowed.