#732 Loggable now inserts the correct values for FK values
This commit is contained in:
parent
d4c399692a
commit
280efdae50
|
@ -71,6 +71,6 @@ describe('Item log path', () => {
|
||||||
const fifthLineCreatedProperty = await nightmare
|
const fifthLineCreatedProperty = await nightmare
|
||||||
.waitToGetProperty(selectors.itemLog.fifthLineCreatedProperty, 'innerText');
|
.waitToGetProperty(selectors.itemLog.fifthLineCreatedProperty, 'innerText');
|
||||||
|
|
||||||
expect(fifthLineCreatedProperty).toEqual('5080000');
|
expect(fifthLineCreatedProperty).toEqual('Coral y materiales similares');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -92,6 +92,8 @@ module.exports = function(Self) {
|
||||||
newInstance: {}
|
newInstance: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
delete instance.originFk;
|
||||||
|
|
||||||
let logModel = definition.settings.log.model;
|
let logModel = definition.settings.log.model;
|
||||||
await ctx.Model.app.models[logModel].create(logRecord, options);
|
await ctx.Model.app.models[logModel].create(logRecord, options);
|
||||||
});
|
});
|
||||||
|
@ -111,10 +113,28 @@ module.exports = function(Self) {
|
||||||
let val1 = ctx.Model.relations[key1];
|
let val1 = ctx.Model.relations[key1];
|
||||||
if (val1.keyFrom == key && key != 'id') {
|
if (val1.keyFrom == key && key != 'id') {
|
||||||
let recordSet = await ctx.Model.app.models[val1.modelTo.modelName].findById(val, options);
|
let recordSet = await ctx.Model.app.models[val1.modelTo.modelName].findById(val, options);
|
||||||
let definition = val1.modelTo.definition;
|
|
||||||
let changedModelValue = definition.settings.log && definition.settings.log.changedModelValue;
|
|
||||||
|
|
||||||
val = (changedModelValue && recordSet && recordSet[changedModelValue]) || (recordSet && recordSet.id) || val; // FIXME preparar todos los modelos con campo name
|
let showField = val1.modelTo && val1.modelTo.definition.settings.log && val1.modelTo.definition.settings.log.showField && recordSet && recordSet[val1.modelTo.definition.settings.log.showField];
|
||||||
|
if (!showField) {
|
||||||
|
const showFieldNames = [
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
'code'
|
||||||
|
];
|
||||||
|
for (field of showFieldNames) {
|
||||||
|
if (val1.modelTo.definition.properties && val1.modelTo.definition.properties[field] && recordSet && recordSet[field]) {
|
||||||
|
showField = field;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showField) {
|
||||||
|
val = recordSet[showField];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
val = recordSet && recordSet.id; // FIXME preparar todos los modelos con campo name
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,18 +181,18 @@ module.exports = function(Self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets the changedModelValue to save and the instances changed in case its an updateAll
|
// Sets the changedModelValue to save and the instances changed in case its an updateAll
|
||||||
let changedModelValue = definition.settings.log.changedModelValue;
|
let showField = definition.settings.log.showField;
|
||||||
let where;
|
let where;
|
||||||
if (changedModelValue && (!ctx.instance || !ctx.instance[changedModelValue]) && ctx.where) {
|
if (showField && (!ctx.instance || !ctx.instance[showField]) && ctx.where) {
|
||||||
changedModelId = [];
|
changedModelId = [];
|
||||||
where = [];
|
where = [];
|
||||||
let changedInstances = await ctx.Model.app.models[definition.name].find({where: ctx.where, fields: ['id', changedModelValue]}, options);
|
let changedInstances = await ctx.Model.app.models[definition.name].find({where: ctx.where, fields: ['id', showField]}, options);
|
||||||
changedInstances.forEach(element => {
|
changedInstances.forEach(element => {
|
||||||
where.push(element[changedModelValue]);
|
where.push(element[showField]);
|
||||||
changedModelId.push(element.id);
|
changedModelId.push(element.id);
|
||||||
});
|
});
|
||||||
} else if (ctx.hookState.oldInstance)
|
} else if (ctx.hookState.oldInstance)
|
||||||
where = ctx.instance[changedModelValue];
|
where = ctx.instance[showField];
|
||||||
|
|
||||||
|
|
||||||
// Set oldInstance, newInstance, userFk and action
|
// Set oldInstance, newInstance, userFk and action
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"log": {
|
"log": {
|
||||||
"model": "ClientLog",
|
"model": "ClientLog",
|
||||||
"relation": "client",
|
"relation": "client",
|
||||||
"changedModelValue": "nickname"
|
"showField": "nickname"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"log": {
|
"log": {
|
||||||
"model": "ClientLog",
|
"model": "ClientLog",
|
||||||
"relation": "client",
|
"relation": "client",
|
||||||
"changedModelValue": "name"
|
"showField": "name"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"log": {
|
"log": {
|
||||||
"model": "ClientLog",
|
"model": "ClientLog",
|
||||||
"relation": "client",
|
"relation": "client",
|
||||||
"changedModelValue": "type"
|
"showField": "type"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
"name": "Client",
|
"name": "Client",
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
"log": {
|
||||||
"model":"ClientLog"
|
"model":"ClientLog",
|
||||||
|
"showField": "id"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"log": {
|
"log": {
|
||||||
"model": "ClientLog",
|
"model": "ClientLog",
|
||||||
"relation": "client",
|
"relation": "client",
|
||||||
"changedModelValue": "description"
|
"showField": "description"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"log": {
|
"log": {
|
||||||
"model": "ItemLog",
|
"model": "ItemLog",
|
||||||
"relation": "item",
|
"relation": "item",
|
||||||
"changedModelValue": "code"
|
"showField": "code"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"log": {
|
"log": {
|
||||||
"model": "ItemLog",
|
"model": "ItemLog",
|
||||||
"relation": "item",
|
"relation": "item",
|
||||||
"changedModelValue": "botanical"
|
"showField": "botanical"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"log": {
|
"log": {
|
||||||
"model": "ItemLog",
|
"model": "ItemLog",
|
||||||
"relation": "item",
|
"relation": "item",
|
||||||
"changedModelValue": "code"
|
"showField": "code"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"log": {
|
"log": {
|
||||||
"model": "ItemLog",
|
"model": "ItemLog",
|
||||||
"relation": "item",
|
"relation": "item",
|
||||||
"changedModelValue": "value"
|
"showField": "value"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
{
|
{
|
||||||
"name": "TicketObservation",
|
"name": "TicketObservation",
|
||||||
"base": "VnModel",
|
"base": "Loggable",
|
||||||
|
"log": {
|
||||||
|
"model": "TicketLog",
|
||||||
|
"relation": "ticket"
|
||||||
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "ticketObservation"
|
"table": "ticketObservation"
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
"base": "Loggable",
|
"base": "Loggable",
|
||||||
"log": {
|
"log": {
|
||||||
"model": "TicketLog",
|
"model": "TicketLog",
|
||||||
"relation": "ticket",
|
"relation": "ticket"
|
||||||
"changedModelValue": "description"
|
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"log": {
|
"log": {
|
||||||
"model": "TicketLog",
|
"model": "TicketLog",
|
||||||
"relation": "ticket",
|
"relation": "ticket",
|
||||||
"changedModelValue": "description"
|
"showField": "description"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"log": {
|
"log": {
|
||||||
"model": "TicketLog",
|
"model": "TicketLog",
|
||||||
"relation": "ticket",
|
"relation": "ticket",
|
||||||
"changedModelValue": "stateFk"
|
"showField": "stateFk"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"log": {
|
"log": {
|
||||||
"model": "TicketLog",
|
"model": "TicketLog",
|
||||||
"relation": "ticket",
|
"relation": "ticket",
|
||||||
"changedModelValue": "ticketFk"
|
"showField": "ticketFk"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
|
|
Loading…
Reference in New Issue