Do not .toObject if already Object

This commit is contained in:
Ritchie Martori 2014-05-05 07:23:12 -07:00 committed by Ritchie Martori
parent cf75f55f73
commit 0866a55cb2
2 changed files with 5 additions and 1 deletions

View File

@ -1,3 +1,4 @@
/*!
* Module exports class Model
*/

View File

@ -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);