Permalink
Browse files

fixed; do not save virtuals in model.update

closes #894
  • Loading branch information...
1 parent 36b05a3 commit 4a22f93531377208cef49ca66cf8a740902f3f8e @aheckmann aheckmann committed May 3, 2012
Showing with 17 additions and 4 deletions.
  1. +1 −1 lib/query.js
  2. +2 −2 lib/schema.js
  3. +14 −1 test/model.update.test.js
View
@@ -1347,7 +1347,7 @@ Query.prototype._walkUpdatePath = function _walkUpdatePath (obj, op, pref) {
var skip = strict &&
!schema &&
- 'adhocOrUndefined' == this.model.schema.pathType(prefix + key);
+ !/real|nested/.test(this.model.schema.pathType(prefix + key));
if (skip) {
delete obj[key];
View
@@ -274,8 +274,8 @@ Object.defineProperty(Schema.prototype, 'requiredPaths', {
});
/**
- * Given a path, returns whether it is a real, virtual, or
- * ad-hoc/undefined path
+ * Given a path, returns whether it is a real, virtual,
+ * nested, or ad-hoc/undefined path.
*
* @param {String} path
* @return {String}
@@ -73,6 +73,9 @@ mongoose.model('BlogPost', BlogPost);
var collection = 'blogposts_' + random();
var strictSchema = new Schema({ name: String, x: { nested: String }}, { strict: true });
+strictSchema.virtual('foo').get(function () {
+ return 'i am a virtual FOO!'
+});
mongoose.model('UpdateStrictSchema', strictSchema);
module.exports = {
@@ -502,10 +505,20 @@ module.exports = {
affected.should.equal(0);
S.findById(s._id, function (err, doc) {
- db.close();
should.strictEqual(null, err);
should.not.exist(doc.ignore);
should.not.exist(doc._doc.ignore);
+
+ S.update({ _id: s._id }, { name: 'Drukqs', foo: 'fooey' }, function (err, affected) {
+ should.strictEqual(null, err);
+ affected.should.equal(1);
+
+ S.findById(s._id, function (err, doc) {
+ db.close();
+ should.strictEqual(null, err);
+ should.not.exist(doc._doc.foo);
+ });
+ });
});
});
});

0 comments on commit 4a22f93

Please sign in to comment.