UNPKG

819 BJavaScriptView Raw
1'use strict';
2
3var
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
19PostSchema.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
31module.exports = {
32 UserSchema: UserSchema,
33 PostSchema: PostSchema
34};