rapidfsub
Best practice for after_action?
In after_action change, I usually load some relationships and call some update actions.
And the action would return a dirty record with old relationships.
Example
defmodule A do
actions do
update :update do
change after_action(fn changeset, record, context ->
record = Ash.load(record, [:b])
B.update!(record.b, params)
{:ok, record}
end)
end
end
end
A.update action calls B.update in after_action.
The result of B.update is not saved anywhere but db.
Therefore, A.update action would return updated A record and old B record.
Should I always call Ash.reload!(record) at the end of after_action?
Or, is there any recommendation how to use after_action?
This is problematic when calling Ash.can with returned A record.
Marked As Solved
zachdaniel
Creator of Ash
defmodule A do
actions do
update :update do
change after_action(fn changeset, record, context ->
record = Ash.load(record, [:b])
# you can modify it directly
{:ok, %{record | b: B.update!(record.b, params)}}
end)
end
end
end
0
Last Post!
rapidfsub
Thanks. I thought it could be an antipattern, by not using functions in Ash.
But it wasn’t. ![]()
0
Popular in Questions
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
I would like to know what is the best IDE for elixir development?
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
Other popular topics
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
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
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
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
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









