check object exists before setting __cachedRelations
This commit is contained in:
parent
052e22ab43
commit
0d7dcdd043
|
@ -390,6 +390,7 @@ Inclusion.include = function (objects, include, options, cb) {
|
|||
var targetId = target[modelToIdName];
|
||||
var objList = targetObjsMap[targetId.toString()];
|
||||
async.each(objList, function (obj, next) {
|
||||
if (!obj) return next();
|
||||
obj.__cachedRelations[relationName].push(target);
|
||||
processTargetObj(obj, next);
|
||||
}, next);
|
||||
|
@ -467,6 +468,7 @@ Inclusion.include = function (objects, include, options, cb) {
|
|||
function linkManyToMany(target, next) {
|
||||
var objList = targetObjsMap[target[relation.keyTo].toString()];
|
||||
async.each(objList, function (obj, next) {
|
||||
if (!obj) return next();
|
||||
obj.__cachedRelations[relationName].push(target);
|
||||
processTargetObj(obj, next);
|
||||
}, next);
|
||||
|
@ -528,11 +530,11 @@ Inclusion.include = function (objects, include, options, cb) {
|
|||
function linkManyToOne(target, next) {
|
||||
//fix for bug in hasMany with referencesMany
|
||||
var targetIds = [].concat(target[relation.keyTo]);
|
||||
async.each(targetIds, function (targetId, proceed) {
|
||||
async.each(targetIds, function (targetId, next) {
|
||||
var obj = objIdMap[targetId.toString()];
|
||||
if (!obj) return proceed();
|
||||
if (!obj) return next();
|
||||
obj.__cachedRelations[relationName].push(target);
|
||||
processTargetObj(obj, proceed);
|
||||
processTargetObj(obj, next);
|
||||
}, next);
|
||||
}
|
||||
}
|
||||
|
@ -620,6 +622,7 @@ Inclusion.include = function (objects, include, options, cb) {
|
|||
function linkOneToMany(target, next) {
|
||||
var objList = targetObjsMap[target[relation.keyTo].toString()];
|
||||
async.each(objList, function (obj, next) {
|
||||
if (!obj) return next();
|
||||
obj.__cachedRelations[relationName] = target;
|
||||
processTargetObj(obj, next);
|
||||
}, next);
|
||||
|
@ -681,7 +684,9 @@ Inclusion.include = function (objects, include, options, cb) {
|
|||
async.each(targets, linkOneToOne, next);
|
||||
function linkOneToOne(target, next) {
|
||||
var sourceId = target[relation.keyTo];
|
||||
if (!sourceId) return next();
|
||||
var obj = objIdMap[sourceId.toString()];
|
||||
if (!obj) return next();
|
||||
obj.__cachedRelations[relationName] = target;
|
||||
processTargetObj(obj, next);
|
||||
}
|
||||
|
@ -748,6 +753,7 @@ Inclusion.include = function (objects, include, options, cb) {
|
|||
var targetId = target[relation.keyTo];
|
||||
var objList = objTargetIdMap[targetId.toString()];
|
||||
async.each(objList, function (obj, next) {
|
||||
if (!obj) return next();
|
||||
obj.__cachedRelations[relationName] = target;
|
||||
processTargetObj(obj, next);
|
||||
}, next);
|
||||
|
|
Loading…
Reference in New Issue