When I was initially thinking about Multi, this was a concern I had as
well. What to do with data that depends on one-another.
I decided not to allow functions in insert/update/delete because of
couple reasons:
* one of the goals of Multi (that I envisioned) was to provide a way
to encode transaction as an inspectable data structure. This has many
benefits - you can defer the execution, pass it around, you could even
destructure in tests without actually running it or running the
database. But in order to do all of it, it has to be as much data and
as little functions as possible. Functions are opaque, you can't look
into them, you need to run them to observe the result.
* a simple (yet controversial) solution to the data dependency on
primary key is to use something that would allow you to generate the
keys client-side. A great solution is UUID. You can generate your
primary key beforehand and insert it where needed yourself.
* there is already a solution for handling dependencies in the form of
nested changesets.
* there is a way to run an arbitrary function
I'm not saying it's a bad idea or that it's something that we
definitely won't do. I'm just trying to explain my reasoning behind
skipping this feature.
Ecto.Multi is something completely new, and I'd say there are yet no
established patterns around it. We're all learning how it can be used
to solve problems.
Regards,
Michał.
>
https://groups.google.com/d/msgid/elixir-ecto/a2f40ed3-92a9-4722-a320-4179173e5da3%40googlegroups.com.