Unexpected behavior, mongoose, schema, validation

14 views
Skip to first unread message

Алексей Фортуна

unread,
Oct 2, 2013, 4:52:35 AM10/2/13
to mongoos...@googlegroups.com

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?

Sergey Lyubka

unread,
Oct 2, 2013, 4:54:46 AM10/2/13
to mongoose-users
Hi Alexey,
This mailing list is for mongoose web server.


--
You received this message because you are subscribed to the Google Groups "mongoose-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-user...@googlegroups.com.
To post to this group, send email to mongoos...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongoose-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages