Force relationnal updates to be done before main model update

This commit is contained in:
Alexandre Bodin 2019-07-11 18:08:50 +02:00
parent 7e45ef91fc
commit 83d762bb53

View File

@ -240,23 +240,19 @@ module.exports = {
return acc;
}, {});
if (!_.isEmpty(values)) {
relationUpdates.push(
this
.forge({
[this.primaryKey]: getValuePrimaryKey(params, this.primaryKey)
})
.save(values, {
patch: true
})
);
} else {
relationUpdates.push(Promise.resolve(_.assign(response, params.values)));
}
// Update virtuals fields.
// Update fields in other collections.
await Promise.all(relationUpdates);
if (!_.isEmpty(values)) {
await this
.forge({
[this.primaryKey]: getValuePrimaryKey(params, this.primaryKey)
})
.save(values, {
patch: true
});
}
return await this
.forge({
[this.primaryKey]: getValuePrimaryKey(params, this.primaryKey)