1 | 'use strict';
|
2 |
|
3 | var
|
4 | mongoose = require('mongoose'),
|
5 | Schema = mongoose.Schema,
|
6 | UserSchema = new Schema({
|
7 | name: String
|
8 | }),
|
9 | PostSchema = new Schema({
|
10 | title: String,
|
11 | author: {type: Schema.Types.ObjectId, ref: 'User'},
|
12 | comments: [{
|
13 | content: String,
|
14 | author: {type: Schema.Types.ObjectId, ref: 'User'}
|
15 | }]
|
16 | }),
|
17 | debug = require('debug')('test');
|
18 |
|
19 | PostSchema.plugin(function (schema) {
|
20 | schema.pre('save', function (next) {
|
21 | debug('*** pre save', this);
|
22 | this.__pre_save_called = true;
|
23 | next();
|
24 | });
|
25 | schema.post('save', function (doc) {
|
26 | debug('*** post save', doc);
|
27 | this.__post_save_called = true;
|
28 | });
|
29 | }, {});
|
30 |
|
31 | module.exports = {
|
32 | UserSchema: UserSchema,
|
33 | PostSchema: PostSchema
|
34 | };
|