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):
- save called
- valid called
- before_validation hook called
- before_validation_on_create/before_validation_on_update called
- validate called
- validate_on_create validate_on_update called
- after_validation called
- after_validation_on_create/after_validation_on_update called
- before_save called
- before_create/before_update called
- create/update (at last)
- after_create/after_update called
- after_save called