Moved inst initialization to place where it used

This commit is contained in:
Wert_Lex 2015-08-25 15:46:50 +03:00
parent 84dc39dfe2
commit 7b497eb58f
1 changed files with 8 additions and 3 deletions

View File

@ -845,7 +845,9 @@ Inclusion.include = function (objects, include, options, cb) {
* @returns {*} * @returns {*}
*/ */
function processTargetObj(obj, callback) { 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 // Calling the relation method on the instance
if (relation.type === 'belongsTo') { if (relation.type === 'belongsTo') {
// If the belongsTo relation doesn't have an owner // If the belongsTo relation doesn't have an owner
@ -853,7 +855,7 @@ Inclusion.include = function (objects, include, options, cb) {
defineCachedRelations(obj); defineCachedRelations(obj);
// Set to null if the owner doesn't exist // Set to null if the owner doesn't exist
obj.__cachedRelations[relationName] = null; obj.__cachedRelations[relationName] = null;
if (obj === inst) { if (isInst) {
obj.__data[relationName] = null; obj.__data[relationName] = null;
} else { } else {
obj[relationName] = null; obj[relationName] = null;
@ -867,7 +869,7 @@ Inclusion.include = function (objects, include, options, cb) {
* @param cb * @param cb
*/ */
function setIncludeData(result, cb) { function setIncludeData(result, cb) {
if (obj === inst) { if (isInst) {
if (Array.isArray(result) && !(result instanceof List)) { if (Array.isArray(result) && !(result instanceof List)) {
result = new List(result, relation.modelTo); result = new List(result, relation.modelTo);
} }
@ -885,6 +887,9 @@ Inclusion.include = function (objects, include, options, cb) {
return setIncludeData(obj.__cachedRelations[relationName], return setIncludeData(obj.__cachedRelations[relationName],
callback); callback);
} }
var inst = (obj instanceof self) ? obj : new self(obj);
//If related objects are not cached by include Handlers, directly call //If related objects are not cached by include Handlers, directly call
//related accessor function even though it is not very efficient //related accessor function even though it is not very efficient
var related; // relation accessor function var related; // relation accessor function