benonymus
Thoughts on multi operation naming
Hey there,
I have been using Ecto.Multi — Ecto v3.14.0 for a while now, and I was wondering what kind of convention do other people follow when they are naming the operations, especially when it is a Multi in an Enum.reduce/3.
With a regular Multi I usually use an atom as the examples do.
For a Multi in an reduce such as:
Enum.reduce(user_ids, Multi.new(), fn user_id, multi ->
blocked_user = Accounts.get_user_by_hash_id(user_id)
changeset = Block.changeset(%Block{}, user, blocked_user)
multi
|> Multi.insert("user_block_#{user.id}_#{blocked_user.id}", changeset)
end)
|> Repo.transaction()
I mostly use a string based on the structs I use, but this relies on both of them having an id and found.
Sometimes I use a uuid appended after the “user_block” for example, and in the docs I saw I could use a tuple.
How about you?
Most Liked
LostKobrakai
You can use any term for naming you multi steps, not just atoms/strings. When mapping/reducing over lists I usually use tuples like {:products, product.id} or something like that.
dimitarvp
I also use tuples. When you don’t know the ID beforehand you can just use a counter. See Enum.with_index.
When inserting I use tuples like {:insert, :product, index}.
jdj_dk
I mostly use a string based on the structs I use, but this relies on both of them having an id and found.
Sometimes I use a uuid appended after the “user_block” for example, and in the docs I saw I could use a tuple.
I do the same as you. It works fine IMO. But perhaps there is a better way? ![]()
Popular in Discussions
Other popular topics
Chat & Discussions>Discussions
Latest on Elixir Forum
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










