Confusion with before_transaction timing and doing changes before manage_relationship
Hello, I am basically trying to use the data from a third party API call to create a related resource in manage_relationship.
Reading the doc I decided that it would make sense to call the API in a
But from what I'm seeing, my change (containing
Here is a reduced example I've quickly set up: (posted below)
If I just run
If I comment out the crashing code and run a full
So my "action change" seems to be executed before the "before transaction" which isn't what I understood from the hooks execution order.
This leads me to 2 questions:
1. Is there something I'm missing with the execution order of the changes?
2. What would be the correct way of providing data changes to manage_relationship outside the transaction? What I've done for now is to include the manage_relationship inside the before_transaction hook, but then it is never executed until the action is actually ran, and then why not put everything in a normal change then?
Thanks
Reading the doc I decided that it would make sense to call the API in a
before_transaction hook. The docs is stating the following execution order for a create action:But from what I'm seeing, my change (containing
manage_relationship) is executing before my before_transaction.Here is a reduced example I've quickly set up: (posted below)
If I just run
for_create, my before_transaction doesn't get executed at all. (the doc for for_create/4 only mentions To have your logic execute only during the action, you can use after_action/2 or before_action/2.), which is already a problem as my manage_relationship depends on the data from the API.If I comment out the crashing code and run a full
Ash.create()!, I get the following logs:So my "action change" seems to be executed before the "before transaction" which isn't what I understood from the hooks execution order.
This leads me to 2 questions:
1. Is there something I'm missing with the execution order of the changes?
2. What would be the correct way of providing data changes to manage_relationship outside the transaction? What I've done for now is to include the manage_relationship inside the before_transaction hook, but then it is never executed until the action is actually ran, and then why not put everything in a normal change then?
Thanks
Solution
Changes/validations run and then when you call the action before_transaction hooks are the first hooks to run
