Skip to content

Commit 44f914b

Browse files
authored
Merge pull request rails#49884 from p8/guides/move-after-commit-warning
Move new warning after example of previous wanring [ci-skip]
2 parents 1370d04 + 3393afb commit 44f914b

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

guides/source/active_record_callbacks.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -554,18 +554,6 @@ WARNING. The code executed within `after_commit` or `after_rollback` callbacks i
554554

555555
WARNING. Using both `after_create_commit` and `after_update_commit` with the same method name will only allow the last callback defined to take effect, as they both internally alias to `after_commit` which overrides previously defined callbacks with the same method name.
556556

557-
WARNING. In the context of a single transaction, if you interact with multiple
558-
loaded objects that represent the same record in the database, there's a crucial
559-
behavior in the `after_commit` and `after_rollback` callbacks to note. These
560-
callbacks are triggered only for the first object of the specific record that
561-
undergoes a change within the transaction. Other loaded objects, despite
562-
representing the same database record, will not have their respective
563-
`after_commit` or `after_rollback` callbacks triggered. This nuanced behavior is
564-
particularly impactful in scenarios where you expect independent callback
565-
execution for each object associated with the same database record. It can
566-
influence the flow and predictability of callback sequences, leading to potential
567-
inconsistencies in application logic following the transaction.
568-
569557
```ruby
570558
class User < ApplicationRecord
571559
after_create_commit :log_user_saved_to_db
@@ -585,6 +573,18 @@ irb> @user.save # updating @user
585573
User was saved to database
586574
```
587575

576+
WARNING. In the context of a single transaction, if you interact with multiple
577+
loaded objects that represent the same record in the database, there's a crucial
578+
behavior in the `after_commit` and `after_rollback` callbacks to note. These
579+
callbacks are triggered only for the first object of the specific record that
580+
undergoes a change within the transaction. Other loaded objects, despite
581+
representing the same database record, will not have their respective
582+
`after_commit` or `after_rollback` callbacks triggered. This nuanced behavior is
583+
particularly impactful in scenarios where you expect independent callback
584+
execution for each object associated with the same database record. It can
585+
influence the flow and predictability of callback sequences, leading to potential
586+
inconsistencies in application logic following the transaction.
587+
588588
### `after_save_commit`
589589

590590
There is also [`after_save_commit`][], which is an alias for using the `after_commit` callback for both create and update together:

0 commit comments

Comments
 (0)