Is there a way to rename multi operations before merging it? I mean without messing with struct internals of course.
Because I’m facing an issue similar to this:
def update_post_multi(post, title) do
changeset = Changeset.change(post, title: title)
Multi.new()
|> Multi.update(:updated_post, post)
end
def update_posts(posts) do
Enum.reduce(posts, Multi.new(), fn post, multi ->
post
|> update_post_multi()
|> multi.prepend(multi)
end)
|> Repo.transaction()
end
I know that this wouldn’t work since names are expected to be unique, also that this can be solved by passing unique tuple keys such as {:updated_post, post.id} but my question is can I actually solve that at the update_posts level without changing the update_post_multi method?
Thank you for the suggestion! That’s probably what I’m going to end up doing, I asked just in case there is an alternative to having to refactor a considerable amount of logic located inside update_post_multi.
You can add an argument the single update post function to give it an [extra] ID and just be done with it. Have that be the last argument and with a default value so it doesn’t break existing code.