acrolink
I am trying to load a book, update it and update the associated record like this:
Multi.new()
|> Multi.run(:get_book, fn _ -> Mango.Books.get_book!(line.book_id) end)
|> Ecto.Multi.run(:update_book, fn %{book: book} ->
Books.update_book(Books.get_book!(book.book_id), %{status: 1})
end)
|> Ecto.Multi.run(:update_associated_record, fn %{book: book} ->
Records.update_record(Records.get_record!(book.record_id), %{
returned_at: :os.system_time(:seconds)
})
end)
|> Repo.transaction()
|> case do
{:ok, result} -> result
{:ok, %{book: book}} -> book
{:ok, %{record: record}} -> record |> whitelist_record_fields
end
This produces this error message:
** (exit) an exception was raised:
** (CaseClauseError) no case clause matching: %Mango.Books.Book{__meta__: #Ecto.Schema.Metadata<:loaded, "books">, author: "Waseem", code: 1116, id: 107, inserted_at: ~N[2018-05-05 11:39:49.688053], institute: #Ecto.Association.NotLoaded<association :institute is not loaded>, institute_id: 1, isbn: "13-1234-78", record_id: 17, records: #Ecto.Association.NotLoaded<association :records is not loaded>, status: :out, title: "Hello World", updated_at: ~N[2018-05-25 16:01:41.752519], year: 1982}
(ecto) lib/ecto/multi.ex:421: Ecto.Multi.apply_operation/5
(elixir) lib/enum.ex:1899: Enum."-reduce/3-lists^foldl/2-0-"/3
(ecto) lib/ecto/multi.ex:411: anonymous fn/5 in Ecto.Multi.apply_operations/5
(ecto) lib/ecto/adapters/sql.ex:576: anonymous fn/3 in Ecto.Adapters.SQL.do_transaction/3
(db_connection) lib/db_connection.ex:1283: DBConnection.transaction_run/4
(db_connection) lib/db_connection.ex:1207: DBConnection.run_begin/3
(db_connection) lib/db_connection.ex:798: DBConnection.transaction/3
(ecto) lib/ecto/repo/queryable.ex:23: Ecto.Repo.Queryable.transaction/4
(mango) lib/mango/records/records.ex:112: anonymous fn/1 in Mango.Records.create_record_in/2 # referring to this line: |> Repo.transaction()
..
..
Any idea what might be going on here? Thank you.
Trending in Questions
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used?
I’ve got two Github accoun...
New
Other Trending Topics
tailwind.com is a Tailwind CSS 4 compiler written in Rust. It is one executable file and needs no Node.js. It is also an Erlang and Elixi...
New
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #elixirconf-us
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
amnu3387
I think you just need to name your first
Multi.run(:get_book...asMulti.run(:book...?acrolink
I wil l try but I believe that is only a name, will not make any difference.
OvermindDL1
The name is how you reference that step in later steps though.
Ecto.Multi very much is a named monadic pipeline.
Elixir really needs some monad stuff built in better so umpteen libraries don’t have to keep remaking it and could just use a behaviour…
amnu3387
It could also be failing on your
.get_zzz!s but if it’s that, when corrected it would still fail when you usefn %{book: book}as you need to use a key that refers to a previous multi “step” I guess - I just recently started using multi thoughacrolink
I have tried the suggestions above, like this:
But I am getting the same error message.
acrolink
Solved..
I have to start with:
OvermindDL1
A couple of things now that I have time to look:
Books.update_book(Books.get_book!(book.book_id), %{status: 1})What is this returning? An
{:ok, result}term?What is this returning? Also an
{:ok, result}term?These will never ever be matched on because
{:ok, result} -> resultwill grab it all first.OvermindDL1
Updateis a different kind of call, it is better to use though, but still,runrequires{:ok, result}/{:error, reason}and I bet that one of those were not.joaquinalcerro
As @OvermindDL1 states, check the retuning value of the Multi.run functions:
Ecto.Multi — Ecto v3.14.0
OvermindDL1
Or rather what you return ‘from’ that function.