Fixed empty objList in linkOneToMany fn (#1287)

This commit is contained in:
somename85 2017-04-05 17:27:34 +03:00 committed by Sakib Hasan
parent 93b89f3a51
commit cbb3f6f98a
1 changed files with 2 additions and 1 deletions

View File

@ -680,6 +680,7 @@ Inclusion.include = function(objects, include, options, cb) {
async.each(targets, linkOneToMany, next); async.each(targets, linkOneToMany, next);
function linkOneToMany(target, next) { function linkOneToMany(target, next) {
var objList = targetObjsMap[target[relation.keyTo].toString()]; var objList = targetObjsMap[target[relation.keyTo].toString()];
if (!objList) return next();
async.each(objList, function(obj, next) { async.each(objList, function(obj, next) {
if (!obj) return next(); if (!obj) return next();
obj.__cachedRelations[relationName] = target; obj.__cachedRelations[relationName] = target;
@ -810,6 +811,7 @@ Inclusion.include = function(objects, include, options, cb) {
function linkOneToMany(target, next) { function linkOneToMany(target, next) {
var targetId = target[relation.keyTo]; var targetId = target[relation.keyTo];
var objList = objTargetIdMap[targetId.toString()]; var objList = objTargetIdMap[targetId.toString()];
if (!objList) return next();
async.each(objList, function(obj, next) { async.each(objList, function(obj, next) {
if (!obj) return next(); if (!obj) return next();
obj.__cachedRelations[relationName] = target; obj.__cachedRelations[relationName] = target;
@ -927,4 +929,3 @@ Inclusion.include = function(objects, include, options, cb) {
} }
} }
}; };