sezaru
Ash.Query.set_argument don't work inside an action
I have a read action that I want to do some checks first.
To do that, I want to create some preparations, the first one will fetch some data, and the others will use that data to do some checks.
Here is the preparations that will fetch data and set as an argument inside the query:
defmodule Core.Feedbacks.Template.Actions.AllFromClass.Preparations.GetClass do
@moduledoc false
alias Core.Feedbacks.Class
alias Ash.Error.Changes.InvalidAttribute
use Ash.Resource.Preparation
def prepare(query, _opts, %{actor: actor}) do
class_id = Ash.Query.get_argument(query, :class_id)
case Class.get!(%{id: class_id}, actor: actor) do
nil ->
# TODO give the error a code
error = InvalidAttribute.exception(message: "Can't find class")
Ash.Query.add_error(query, error)
class ->
Ash.Query.set_argument(query, :class, class)
end
end
end
As you can see, I get a class_id argument, fetch the class with it, and then I use Ash.Query.set_argument to add the class argument.
The problem is that this call doesn´t do anything, if I dbg the query after the set_argument call, the arguments field only contains the class_id argument.
Marked As Solved
zachdaniel
Creator of Ash
Correct, to store values to be used later on/passed between changes, you’d use the context.
0
Popular in Questions
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
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
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
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
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
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Other popular topics
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
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 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
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
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
- #forms
- #api
- #metaprogramming
- #security
- #hex










