Adding new changeset arguments in `before_action`
Hi, I'm having a bit of trouble understanding the order in which changes get executed within an update action and how to set arguments. Suppose I have something like:
Running
:foo
on a resource prints the following in the IEx:
where the value associated with nil
is the nested_resource.id
.
I have two questions:
1. At what point do changes that are not before_action
, etc get run?
2. Is this a bug that an argument gets a key of nil
instead of :nested_resource_id
?8 Replies
https://hexdocs.pm/ash/actions.html#complete-lifecycle-flow
THe changes run first
and then any before actions that were added run after that
How is it that in the example above the arguments get populated with
:nested_resource_id
's value under nil
key? 🤔🤔 I have no idea actually
Does that not happen if you remove the
before_action
change above it?
THat seems unrelated to me TBHif instead of just doing
set_argument
I do something hacky like Map.put(changeset, :arguments, Map.put(changeset.arguments, :nested_resource_id, nested_resource.id))
, then the debug actually prints:
oh
wow
its because there is no such argument with that name
it must be a bug w/ how we handle that
please open an issue
you can't
set_argument
for args taht don't exitah damn, I was kind of depending on running
set_argument
to add new arguments dynamically 🫣
(in my hacky way)You can use
set_context
and read from context
You can also have private argumentsah yes, that's the right approach. I'll open an issue about the
nil
thing