From ba156a2e4207fd6e7eb090867d2e1e9773c8881c Mon Sep 17 00:00:00 2001 From: bernat Date: Fri, 27 Nov 2020 11:56:41 +0100 Subject: [PATCH] log refactor --- loopback/util/log.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/loopback/util/log.js b/loopback/util/log.js index cf12dcb2f..baba3e827 100644 --- a/loopback/util/log.js +++ b/loopback/util/log.js @@ -5,7 +5,6 @@ */ exports.translateValues = async(instance, changes) => { const models = instance.app.models; - function getRelation(instance, property) { const relations = instance.definition.settings.relations; for (let relationName in relations) { @@ -38,12 +37,18 @@ exports.translateValues = async(instance, changes) => { for (let property in properties) { const relation = getRelation(instance, property); const value = properties[property]; - let finalValue = value; + if (relation) { + let fieldsToShow = ['alias', 'name', 'code', 'description']; + const log = instance.definition.settings.log; + + if (log && log.showField) + fieldsToShow = log.showField; + const model = relation.model; const row = await models[model].findById(value, { - fields: ['alias', 'name', 'code', 'description'] + fields: fieldsToShow }); const newValue = getValue(row); if (newValue) finalValue = newValue; -- 2.40.1