Unexpected behavior
I have some model:
//test.js
var mongoose = require('../utils/mongoose');
var schema1 = new mongoose.Schema({ name: String })
var schema2 = new mongoose.Schema({ objectsArray: [schema1] });
schema1.pre('validate', function(next) {
console.log('pre validate schema1');
next();
});
module.exports = mongoose.model('Schema2', schema2);
Do save:
var o = new require('test')({ objectsArray: [{ name: 'Alex' }] });
o.save(function(err){ console.log('saved'); });
After, in console i get:
pre validate schema1 pre validate schema1 saved
The question is, Why?schema1.pre('validate')
- appears 2 times, but i expect 1 time?
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
var mongoose = require('mongoose');
mongoose.connect('mongodb://127.0.0.1:27017/test');
mongoose.connection.on('open', function() {
var schema1 = new mongoose.Schema({
name: String
})
schema1.pre('validate', function(next) {
console.log('pre validate');
next();
});
var schema2 = new mongoose.Schema({
objectsArray: [schema1]
});
Schema2 = mongoose.model('Schema2', schema2);
var o = Schema2({ objectsArray: [{ name: 'Alex' }] });
o.save(function(err){ console.log('saved'); });
});
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.