Correctly handle null relations on local relation fields

master
Sven Slootweg 5 months ago
parent 75a40d851f
commit 786f27fbbf

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

Loading…
Cancel
Save