Mongo Mapper

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:

class Monkey
  include MongoMapper::Document
  before_save :do_something_before_save

  private
  def do_something_before_save
  end
end
Fork me on GitHub