From c8322eea316a824c4c734453b3fb77625332c041 Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Mon, 29 Oct 2012 04:05:05 +0400 Subject: [PATCH] Fix instanceof checking --- lib/abstract-class.js | 6 ++++-- test/common_test.js | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/abstract-class.js b/lib/abstract-class.js index 960b4e73..4882a902 100644 --- a/lib/abstract-class.js +++ b/lib/abstract-class.js @@ -161,10 +161,10 @@ AbstractClass.create = function (data, callback) { var obj = null; // if we come from save - if (data instanceof AbstractClass && !data.id) { + if (data instanceof this && !data.id) { obj = data; data = obj.toObject(true); - this.prototype._initProperties.call(obj, data, false); + obj._initProperties(data, false); create(); } else { obj = new this(data); @@ -188,6 +188,8 @@ AbstractClass.create = function (data, callback) { this._adapter().create(modelName, this.constructor._forDB(data), function (err, id) { if (id) { + obj.__data.id = id; + obj.__dataWas.id = id; defineReadonlyProp(obj, 'id', id); } done.call(this, function () { diff --git a/test/common_test.js b/test/common_test.js index 6c243f13..9d654368 100644 --- a/test/common_test.js +++ b/test/common_test.js @@ -855,7 +855,6 @@ function testOrm(schema) { User.find(user.id, function (err, user) { test.ok(user !== u); test.equal(user.passwd, 'qwertysalt'); - console.log(user.id); User.all({where: {passwd: 'qwertysalt'}}, function (err, users) { test.ok(users[0] !== user); test.equal(users[0].passwd, 'qwertysalt');