From 0866a55cb215f27282cd8ea5c36e46a0b2cd33e9 Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Mon, 5 May 2014 07:23:12 -0700 Subject: [PATCH] Do not .toObject if already Object --- lib/dao.js | 1 + lib/model.js | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/dao.js b/lib/dao.js index 267d609e..671d4a00 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -1,3 +1,4 @@ + /*! * Module exports class Model */ diff --git a/lib/model.js b/lib/model.js index 3a3b3999..ba1a1e87 100644 --- a/lib/model.js +++ b/lib/model.js @@ -242,10 +242,13 @@ ModelBaseClass.prototype.toObject = function (onlySchema, removeHidden) { var self = this; var Model = this.constructor; + // if it is already an Object + if(Model === Object) return self; + var strict = this.__strict; var schemaLess = (strict === false) || !onlySchema; - this.constructor.forEachProperty(function (propertyName) { + Model.forEachProperty(function (propertyName) { if(removeHidden && Model.isHiddenProperty(propertyName)) return; if (self[propertyName] instanceof List) { data[propertyName] = self[propertyName].toObject(!schemaLess, removeHidden);