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.