mongoose-compliant-paranoia
Version:
A plugin to complay with Rails paranoia plugins so we dont query 'deleted' documents
48 lines (36 loc) • 751 B
JavaScript
// Generated by CoffeeScript 1.6.2
var path;
path = 'deleted_at';
/*
this.install mongoose
see test/
*/
exports.install = function(mongoose) {
var originalCast;
originalCast = mongoose.Query.prototype.cast;
mongoose.Query.prototype.cast = function(model, obj) {
if (this.op !== 'remove') {
obj || (obj = this._conditions);
this.where(path, {
$exists: false
});
}
return originalCast(model, obj);
};
return true;
};
/*
schema.plugin this.plugin
see test/
*/
exports.plugin = function(schema, options) {
var index, newField;
newField = {};
newField[path] = Date;
schema.add(newField);
index = {};
index[path] = 1;
return schema.index(index, {
unique: false
});
};