The ActiveRecord Hook Execution Chain

January 5, 2010

Just thought I’d post some copypasta from the Rails documentation. Rails’ documentation is massive and they hide this information where it might be hard to find tidbits like this.

ActiveRecord executes hooks in the following order (source):

  1. save called
  2. valid called
  3. before_validation hook called
  4. before_validation_on_create/before_validation_on_update called
  5. validate called
  6. validate_on_create validate_on_update called
  7. after_validation called
  8. after_validation_on_create/after_validation_on_update called
  9. before_save called
  10. before_create/before_update called
  11. create/update (at last)
  12. after_create/after_update called
  13. after_save called