From 16741d66c9e8ad6bd2af0c42bc6a6de5db799b78 Mon Sep 17 00:00:00 2001 From: Marcelo Luiz Onhate Date: Wed, 3 Jul 2024 11:39:10 -0300 Subject: [PATCH] fix: log error on missing required fields when finding with fields selection --- src/Model.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Model.js b/src/Model.js index a2d459a..f514a86 100644 --- a/src/Model.js +++ b/src/Model.js @@ -1136,11 +1136,12 @@ export class Model { } } else if (value === undefined) { if (field.required) { - /* - Transactions transform the properties to return something, but - does not have all the properties and required fields may be missing) + /* + Transactions transform the properties to return something, but + does not have all the properties and required fields may be missing). + Also find operation with fields selections may not include required fields. */ - if (!params.transaction) { + if (!params.transaction && !params.fields) { this.table.log.error(`Required field "${name}" in model "${this.name}" not defined in table item`, { model: this.name, raw, params, field, }) @@ -1607,7 +1608,7 @@ export class Model { delete properties[name] if (this.getPartial(field, params) === false && pathname.match(/[[.]/)) { /* - Partial disabled for a nested object + Partial disabled for a nested object Don't create remove entry as the entire object is being created/updated */ continue @@ -2034,7 +2035,7 @@ export class Model { /* Return if a field supports partial updates of its children. - Only relevant for fields with nested schema + Only relevant for fields with nested schema */ getPartial(field, params) { let partial = params.partial