I have done some tests, and I have find out that after_create is called before than after_save (in Rails 2.3.9)
Is that correct ?
thanks
There is a slight but important difference between after_save and after_commit callbacks. after_commit is invoked when a database transaction reaches committed state. In case a transaction fails, for instance, while creating a record, after_commit is not invoked by Active Record, but after_save will have run by then.
The callback order is as following:after_validation. after_validation_on_create / after_validation_on_update. before_save. before_create.
When a transaction completes, the after_commit or after_rollback callbacks are called for all models created, updated, or destroyed within that transaction.
around_save. Called before a new or existing object is saved until yield is invoked within the method triggered by the callback. Calling yield causes the object to be saved and then any proceeding code in the method will execute.
Yes, here's the order:
# (1) before_validation
# (2) before_validation_on_create
# (3) after_validation
# (4) after_validation_on_create
# (5) before_save
# (6) before_create
# (7) after_create
# (8) after_save
Found here:
http://ar.rubyonrails.org/classes/ActiveRecord/Callbacks.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With