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);