How to make 'actor' available in nested forms' action
I have
Ash.set_actor(current_user) in the
mount function of a liveview that contains a nested form. The create/update actions of the main (posts) and sub form (comments), both of which includes
change fn changeset, %{actor: actor}, the variable
actor passes the proper user map for
post , but nil for
comment`. Also tried passing actor like below, but it didn't help either. Is there anything else I need to do to make it available in the nested forms' action as well?
8 Replies
🤔 interesting...that could be a bug potentially
could you open an issue on
ash_phoenix
for this?Will do. By the way, when I pass in
actor
like shown above in the for_update
statement, and don't have Ash.set_actor
in the mount
function, actor
is nil even in the main form (post)'s create action. That doesn't sound right, does it? I'm wondering if I'm missing something bovious.Yeah, I think I can see whats going on there. Basically the form itself needs to pick up the actor from context, not just leave it to the underlying changeset or query. The reason for this is that it explicitly sets that context for nested forms.
I see.
If you provide the actor explicitly as an option I think that will be a workaround
I won’t be able to fix in the next few days because I’m at ElixirConf
Lucky you. What do you mean by providing the actor as an option? Can you please elaborate a little bit?
When creating a form, you can say
actor: the actor
Thank you. It worked!.