I was wondering in what order are callbacks and validations called when an ActiveRecord object is created.
Let’s say I have some custom validations & callbacks l
Here is a list with all the available Active Record callbacks, listed in the same order in which they will get called during the respective operations:
before_validationafter_validationbefore_savearound_savebefore_createaround_createafter_createafter_saveafter_commit/after_rollbackbefore_validationafter_validationbefore_savearound_savebefore_updatearound_updateafter_updateafter_saveafter_commit/after_rollbackbefore_destroyaround_destroyafter_destroyafter_commit/after_rollbackafter_save runs both on create and update, but always after the more specific callbacks after_create and after_update, no matter the order in which the macro calls were executed.
before_destroy callbacks should be placed before dependent: :destroy associations (or use the prepend: true option), to ensure they execute before the records are deleted by dependent: :destroy.