From 5175ee63368231388b4136e58c3a50aa7a5f45bd Mon Sep 17 00:00:00 2001 From: Jim Laurie Date: Thu, 17 May 2018 14:56:53 +0200 Subject: [PATCH] Fix media relation update --- packages/strapi-mongoose/lib/relations.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/strapi-mongoose/lib/relations.js b/packages/strapi-mongoose/lib/relations.js index 96bdb546d1..5a28e26c4e 100644 --- a/packages/strapi-mongoose/lib/relations.js +++ b/packages/strapi-mongoose/lib/relations.js @@ -21,7 +21,8 @@ module.exports = { .findOne({ [this.primaryKey]: params[this.primaryKey] || params.id }) - .populate(this.associations.map(x => x.alias).join(' ')); + .populate(this.associations.map(x => x.alias).join(' ')) + .lean(); // Only update fields which are on this document. const values = params.parseRelationships === false ? params.values : Object.keys(JSON.parse(JSON.stringify(params.values))).reduce((acc, current) => { @@ -270,13 +271,17 @@ module.exports = { However the upload doesn't need this method. It only uses the `removeRelationMorph`. */ - const entry = ( + let entry = ( await this .findOne({ [this.primaryKey]: getValuePrimaryKey(params, this.primaryKey) }) - .toJSON() ); + + if (entry) { + entry = entry.toJSON(); + } + const value = []; // Retrieve association.