I am using middleware to do some pre-processing before removing a record from the database. However it would be very useful if I could pass on some information about the results of this pre-processing from the middleware to the model remove callback. Is this possible somehow?
Movie.pre('remove', function(next) {
var result = true;
next();
});
movie.remove(function(err, result) {
if (result === true) {
// do something
}
});
You can't inject result
into the remove
callback parameters, but this will work:
Movie.pre('remove', function(next) {
this.result = true; // Add a result property to the movie object being removed
next();
});
movie.remove(function(err) {
if (movie.result === true) { // result property is available from the middleware
// do something
}
});