benonymus

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

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

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

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? :slight_smile:

Where Next?

Popular in Discussions Top

AstonJ
Are there any Elixir or Erlang libraries that help with this? I’ve been thinking how streaming services like twitch have exploded recentl...
New
mbenatti
Following https://github.com/tbrand/which_is_the_fastest |> https://raw.githubusercontent.com/tbrand/which_is_the_fastest/master/imgs...
New
tmbb
This is a post to discuss the new Phoenix LiveView functionality. From Chris’s talk, it appears that they generate all HTML on the serve...
342 18634 126
New
chuck
Let me start by stating an assumption: Phoenix is a great approach to building REST APIs. There are many reasons for this, but I will ass...
New
opsb
We’re considering our architecture from a viewpoint of scaling our traffic heavily over the next 6 months. Our current deployment is runn...
New
pillaiindu
I want to convert a Phoenix LiveView CRUD website to a CRUD mobile app. What do you think is the easiest way to do so?
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement