Version 2.5.0 Release
This release focuses on improving the hooks system to allow a bit more flexibility and to make managing things easier from a maintenance perspective.
We've renamed existing hooks and added new ones with the following signatures.
{
hooks: {
creating: function([done]) { },
saving: function(changes, [done]) { },
retrieved: function([done]) { },
ready: function([done]) { }
}
}
A quick description of what these hooks do can be found in the README, but I've copied that section here for your convenience.
- creating([done])
Called before an object is first stored in the database,this
is set to the contents of the object being stored - allowing modification of the object prior to its insertion into the database. - saving(changes[, done])
Called before an exisiting object is updated in the database (not called forModel.update()
) withthis
set to the instance of the object being updated and the first argument always being the object changeset (MongoDB update syntax), allowing you to perform custom updates each time an object is saved. - retrieved([done])
Called after an object has been retrieved from the database, but before it is wrapped into an Instance. The hook'sthis
is set to the database document received - and will not have undergone any preprocessing yet. - ready([done])
Called after an object has undergone preprocessing and has been wrapped into an Instance, allowing you to set non-persistent properties on the object (for example, retrieval time for a cache).