From 77559b267fa6ca841f9b8dcdb2d30cced0a23972 Mon Sep 17 00:00:00 2001 From: Robert P Date: Mon, 18 Jan 2016 18:27:06 +1030 Subject: [PATCH] Avoid loading BelongsTo relations with falsey ids --- src/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 599bc3b..1647ba2 100644 --- a/src/index.js +++ b/src/index.js @@ -159,10 +159,13 @@ function loadWithRelations (items, resourceConfig, options) { }) } else if (def.type === 'belongsTo' || (def.type === 'hasOne' && def.localKey)) { if (instance) { - task = this.find(resourceConfig.getResource(relationName), DSUtils.get(instance, def.localKey), __options).then(relatedItem => { - instance[def.localField] = relatedItem - return relatedItem - }) + let id = DSUtils.get(instance, def.localKey) + if (id) { + task = this.find(resourceConfig.getResource(relationName), id, __options).then(relatedItem => { + instance[def.localField] = relatedItem + return relatedItem + }) + } } else { task = this.findAll(resourceConfig.getResource(relationName), { where: {