Skip to content

Commit

Permalink
Move new warning after example of previous wanring [ci-skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
p8 committed Nov 1, 2023
1 parent 1370d04 commit 3393afb
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions guides/source/active_record_callbacks.md
Expand Up @@ -554,18 +554,6 @@ WARNING. The code executed within `after_commit` or `after_rollback` callbacks i

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.

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

```ruby
class User < ApplicationRecord
after_create_commit :log_user_saved_to_db
Expand All @@ -585,6 +573,18 @@ irb> @user.save # updating @user
User was saved to database
```

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

### `after_save_commit`

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

0 comments on commit 3393afb

Please sign in to comment.