forked from maxiejbe/baucis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModel.js
More file actions
34 lines (29 loc) · 1.03 KB
/
Model.js
File metadata and controls
34 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var deco = require('deco');
var mongoose = require('mongoose');
var pluralize = require('pluralize');
var Model = module.exports = deco(function (options, protect) {
var model = this;
protect.property('singular');
protect.property('plural');
protect.property('locking', false);
protect.property('lastModified');
model.deselected = function (path) {
var deselected = [];
// Store naming, model, and schema.
// Find deselected paths in the schema.
model.schema.eachPath(function (name, path) {
if (path.options.select === false) deselected.push(name);
});
if (arguments.length === 0) return deselected;
else return (deselected.indexOf(path) !== -1);
};
model.singular(model.modelName);
model.plural(pluralize(model.singular()));
});
// Wrap the mongoose model function to add this mixin to all registered models.
var originalMongooseModel = mongoose.model;
mongoose.model = function () {
var m = originalMongooseModel.apply(mongoose, arguments);
if (!m.singular) Model.apply(m);
return m;
};