Developer. Designer. Jason Ormand

Blog/Portfolio for a Developer/Designer/Entrepreneur

MongoMapper callback order

January 26th 2013 by Jason Ormand

I recently started using MongoMapper for a project at work. The documentation is pretty sparse and I needed to confirm the precise order of callbacks, per action. So I wrote some simple test code to do just that. Here are the results:

.create

  1. before_validation
  2. validate
  3. after_validation
  4. before_save
  5. before_create
  6. after_create
  7. after_save

.save

  1. before_validation
  2. validate
  3. after_validation
  4. before_save
  5. before_update
  6. after_update
  7. after_save

.update_attributes!

  1. before_validation
  2. validate
  3. after_validation
  4. before_save
  5. before_update
  6. after_update
  7. after_save

.destroy

  1. before_destroy
  2. after_destroy

.touch

  1. * no callabacks *