From 7b497eb58f5fcbd68e9d25ee73d097c1867dff97 Mon Sep 17 00:00:00 2001 From: Wert_Lex Date: Tue, 25 Aug 2015 15:46:50 +0300 Subject: [PATCH] Moved inst initialization to place where it used --- lib/include.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/include.js b/lib/include.js index f261b9ea..d3428e33 100644 --- a/lib/include.js +++ b/lib/include.js @@ -845,7 +845,9 @@ Inclusion.include = function (objects, include, options, cb) { * @returns {*} */ function processTargetObj(obj, callback) { - var inst = (obj instanceof self) ? obj : new self(obj); + + var isInst = obj instanceof self; + // Calling the relation method on the instance if (relation.type === 'belongsTo') { // If the belongsTo relation doesn't have an owner @@ -853,7 +855,7 @@ Inclusion.include = function (objects, include, options, cb) { defineCachedRelations(obj); // Set to null if the owner doesn't exist obj.__cachedRelations[relationName] = null; - if (obj === inst) { + if (isInst) { obj.__data[relationName] = null; } else { obj[relationName] = null; @@ -867,7 +869,7 @@ Inclusion.include = function (objects, include, options, cb) { * @param cb */ function setIncludeData(result, cb) { - if (obj === inst) { + if (isInst) { if (Array.isArray(result) && !(result instanceof List)) { result = new List(result, relation.modelTo); } @@ -885,6 +887,9 @@ Inclusion.include = function (objects, include, options, cb) { return setIncludeData(obj.__cachedRelations[relationName], callback); } + + var inst = (obj instanceof self) ? obj : new self(obj); + //If related objects are not cached by include Handlers, directly call //related accessor function even though it is not very efficient var related; // relation accessor function