From 786f27fbbfea2253893e6a40ddc45a985588bd6a Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Thu, 1 Aug 2024 19:02:55 +0200 Subject: [PATCH] Correctly handle null relations on local relation fields --- src/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 71c5520..c537af1 100644 --- a/src/index.js +++ b/src/index.js @@ -216,7 +216,13 @@ module.exports = { if (remoteTableLayout[foreignKey.column].isPrimaryKey === true) { let field = [ localField, async function (_, { $make, $getProperty }) { - return $make(`dlayer-knex.${foreignKey.table}`, { id: await $getProperty(this, name) }) + let id = await $getProperty(this, name); + + if (id != null) { + return $make(`dlayer-knex.${foreignKey.table}`, { id: id }); + } else { + return null; + } }]; selfRelationFields.push(field);