Callbacks
MongoMapper makes use of the ActiveModel::Callbacks, so they are identical to Rails.
The callbacks supported are the same as on ActiveModel, the callbacks provided are:
- before_validation
- after_validation
- before_save
- after_save
- before_create
- after_create
- before_update
- after_update
- before_destroy
- after_destroy
For embedded documents you have similar callbacks:
- before_validation
- after_validation
- before_save
- after_save
- before_create
- after_create
- before_update
- after_update
- before_destroy
- after_destroy
Example
The callbacks are set on your model like this: