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
Hello, how can I check the Phoenix version ?
Thanks !
New
I would like to know what is the best IDE for elixir development?
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Other popular topics
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
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
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something…
Haskell reminds me of Java, and e...
New
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
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









