I have an invitation resource that has a status
, user_id
among other attributes. I use AshStateMachine to update the status
attribute, to accepted
when the invited user registers in the app, and to expired
, when the invitation expires.
When the invitee registers, I need to save their user ID in the invitation.user_id
field, as well as transition the invitation status to accepted
. I do it this way, in an after_action
hook:
%{status: :success} =
Invitation.update(invitation, %{user_id: user_id}, authorize?: false)
%{status: :success} = Invitation.accept(invitation, authorize?: false)
This works, but I was wondering if it is possible to pass the user_id
to the Invitation.accept/2
action, which is used by AshStateMachine, so that I don’t have to call a separate action (Invitation.update/3
) to update the user ID field.