You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/topics/actions/actions.md
+14-20Lines changed: 14 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -286,20 +286,18 @@ Ash resource actions follow a well-defined lifecycle that ensures proper data va
286
286
-**Transaction Phase** - Operations within database transaction
287
287
-**Post-Transaction Phase** - Operations after database transaction
288
288
289
-
#### Important Notes:
289
+
#### Important Note:
290
290
291
-
-**Query Actions**: Read queries do not currently have `before_transaction`, `after_transaction`, or `around_transaction` callbacks
292
291
-**Around Action Behavior**: `around_action` hooks do not complete their "end" phase if the action fails
293
-
-**Generic Actions**: Generic actions support validations, preparations, and all hook types including transaction-level hooks (before_transaction/after_transaction/around_transaction).
AFTER_TRANS["after_transaction<br/>(Always runs - success/error)<br/>🚫 Not available for read/query actions"] --> AROUND_END["around_transaction (end)<br/>🚫 Not available for read/query actions"]
-**Inside Transaction**: Action preparations/validations/changes, Global preparations/validations/changes, `around_action`, `before_action`, `after_action`
571
570
572
571
#### Error Handling
573
572
-`after_action` only runs on successful operations
574
573
-`around_action` (end) only runs on successful operations
575
-
-`after_transaction` always runs (success and error) - available for create/update/destroy/generic actions
574
+
-`after_transaction` always runs (success and error)
576
575
-`after_transaction` can change the final result - can transform errors into successes (useful for retries)
577
576
- Transaction rollback occurs automatically on errors
578
577
@@ -592,29 +591,24 @@ The hooks execute in the following order (as of Ash 3.0+):
592
591
### Action Type Differences
593
592
594
593
#### Create/Update/Destroy Actions
595
-
- Have full lifecycle including all transaction hooks
596
-
- Support `before_transaction`, `after_transaction`, `around_transaction`
597
594
- Run in transactions by default, unless no hooks of any kind are added to the changeset.
598
595
- Have complete error handling and rollback capabilities
599
596
600
597
#### Read/Query Actions
601
-
- Do not support `before_transaction`, `after_transaction`, or `around_transaction` hooks
602
-
- Only support `before_action`, `after_action`, and `around_action` hooks
603
598
- Do not run in transactions by default
604
599
- Focus on data retrieval and filtering
605
600
606
601
#### Generic Actions
607
-
- Support validations, preparations, and all hook types (`before_action`, `after_action`, `around_action`, `before_transaction`, `after_transaction`, `around_transaction`)
602
+
- Support validations, preparations, and all hook types
608
603
- Can run in transactions by setting `transaction? true` in the action definition
609
-
- Transaction hooks work for both transactional and non-transactional generic actions
610
604
- Focus on custom business logic and operations
611
605
612
606
### Best Practices
613
607
614
-
- Use `before_transaction` for external API calls (create/update/destroy/generic actions only)
608
+
- Use `before_transaction` for external API calls
615
609
- Use `before_action` for final data modifications
616
610
- Use `after_action` for transactional side effects
617
-
- Use `after_transaction` for external notifications (create/update/destroy/generic actions only)
611
+
- Use `after_transaction` for external notifications
618
612
- Use `after_transaction` for retry mechanisms and result transformation
619
613
- Keep transaction phase operations fast and focused
0 commit comments