Exclude timestamps on save and updates in queries

This commit is contained in:
Alexandre Bodin 2019-08-05 16:55:04 +02:00
parent c17a718f25
commit 472553b3b2
2 changed files with 13 additions and 0 deletions

View File

@ -2,6 +2,13 @@ services:
- postgresql
- mysql
addons:
postgresql: '10'
apt:
packages:
- postgresql-10
- postgresql-client-10
sudo: required
dist: trusty

View File

@ -19,6 +19,8 @@ module.exports = function createQueryBuilder({ model, modelKey, strapi }) {
return model.attributes[key].type === 'group';
});
const timestamps = _.get(model, ['options', 'timestamps'], []);
// Returns an object with relation keys only to create relations in DB
const pickRelations = values => {
return _.pick(values, assocKeys);
@ -29,6 +31,10 @@ module.exports = function createQueryBuilder({ model, modelKey, strapi }) {
// Returns an object without relational keys to persist in DB
const selectAttributes = values => {
return _.pickBy(values, (value, key) => {
if (Array.isArray(timestamps) && timestamps.includes(key)) {
return false;
}
return !excludedKeys.includes(key) && _.has(model.allAttributes, key);
});
};