-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsession.js
More file actions
41 lines (35 loc) · 1020 Bytes
/
Copy pathsession.js
File metadata and controls
41 lines (35 loc) · 1020 Bytes
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
35
36
37
38
39
40
41
var mongoose = require('mongoose');
var deepPopulate = require('mongoose-deep-populate')(mongoose);
const sessionSchema = new mongoose.Schema({
name: String,
user: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
svg: String,
output: String,
input: String,
grammar: String,
markdown: String,
originalUrl: String,
private: {type: Boolean, default: false},
height: Number,
width: Number,
parent: {type: mongoose.Schema.Types.ObjectId, ref: 'Session'},
children: [{type: mongoose.Schema.Types.ObjectId, ref: 'Session'}]
});
var autoPopulateChildren = function(next) {
this.populate('children');
next();
};
var autoPopulateParent = function(next) {
this.populate('parent');
next();
};
sessionSchema
.pre('findOne', autoPopulateChildren)
.pre('find', autoPopulateChildren);
sessionSchema.plugin(deepPopulate, {
whitelist: [
// 'children',
// 'parent'
]
});
module.exports = mongoose.model('Session',sessionSchema);