From 83d762bb533345ab4cd2063b9fe1a585541731b0 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Thu, 11 Jul 2019 18:08:50 +0200 Subject: [PATCH] Force relationnal updates to be done before main model update --- .../strapi-hook-bookshelf/lib/relations.js | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/strapi-hook-bookshelf/lib/relations.js b/packages/strapi-hook-bookshelf/lib/relations.js index 07d104be08..cf048c3d9c 100644 --- a/packages/strapi-hook-bookshelf/lib/relations.js +++ b/packages/strapi-hook-bookshelf/lib/relations.js @@ -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)