Help with multi-step resource creation in Ash (Phoenix + React)
I’m building a multi‑tenant app with this structure:
user → organization → establishment → establishment_user
In my flow, a user creates both an organization and an establishment, and the system automatically creates the establishment_user behind the scenes.
What I have:
My questions:
- Could I have used
- Do all three actions run in a single transaction?
- How can I implement policies correctly in this setup? With
This setup is working btw (aside from policies), just making sure it’s the right way to do it.
user → organization → establishment → establishment_user
In my flow, a user creates both an organization and an establishment, and the system automatically creates the establishment_user behind the scenes.
What I have:
My questions:
- Could I have used
manage_relationship/4 for this, or is after_action/3 my only option due to setting different tenants?- Do all three actions run in a single transaction?
- How can I implement policies correctly in this setup? With
manage_relationship, I could use accessing_from/2 in my policies, but that doesn’t seem to work when using after_action, so I’m bypassing policies entirely for nowThis setup is working btw (aside from policies), just making sure it’s the right way to do it.
Solution
1.
2. all run in the same transaction, the first action call opens the transaction and all the after action starts the next action in the same transaction
3 . all
after_action was the right choice, you can't set a different tenant with manage_relationship AFAIK2. all run in the same transaction, the first action call opens the transaction and all the after action starts the next action in the same transaction
3 . all
accessing_from is checking is a certain value in the context, so you could just manually set the context when calling the other actions inside after_action