Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed; set isNew on embedded docs to false after save

  • Loading branch information...
commit ec5c757b231383094d0386b5528aaa1d25f8ffcc 1 parent d054e84
@aheckmann aheckmann authored
Showing with 13 additions and 4 deletions.
  1. +2 −2 lib/model.js
  2. +11 −2 lib/types/document.js
View
4 lib/model.js
@@ -238,8 +238,9 @@ Model.prototype.init = function (doc, query, fn) {
function makeSaveHandler(promise, self) {
return function (err) {
if (err) return promise.error(err);
- promise.complete(self);
+ self.isNew = false;
self.emit('save', self);
+ promise.complete(self);
promise = null;
self = null;
};
@@ -266,7 +267,6 @@ Model.prototype.save = function (fn) {
if (this.isNew) {
// send entire doc
this.collection.insert(this.toObject({ depopulate: 1 }), options, complete);
- this.isNew = false;
// clear atomics
this._dirty().forEach(function (dirt) {
View
13 lib/types/document.js
@@ -15,9 +15,19 @@ var Document = require('../document')
*/
function EmbeddedDocument (obj, parentArr) {
+ var self;
+
this.parentArray = parentArr;
- this.parent = parentArr.parent;
+ this.parent = parentArr._parent;
Document.call(this, obj);
+
+ if (this.parent) {
+ self = this;
+ this.parent.on('save', function () {
+ self.isNew = false;
+ self.emit('save');
+ });
+ }
};
/**
@@ -68,7 +78,6 @@ EmbeddedDocument.prototype.markModified = function (path) {
EmbeddedDocument.prototype.save = function(fn) {
if (fn)
fn(null);
- this.emit('save', this);
return this;
};
Please sign in to comment.
Something went wrong with that request. Please try again.