diff --git a/packages/strapi-hook-mongoose/lib/relations.js b/packages/strapi-hook-mongoose/lib/relations.js index 8fc4832a1d..3acd9c728d 100644 --- a/packages/strapi-hook-mongoose/lib/relations.js +++ b/packages/strapi-hook-mongoose/lib/relations.js @@ -97,13 +97,13 @@ module.exports = { acc[current] = params.values[current]; } else if (response[current] && _.isArray(response[current]) && current !== 'id') { // Records to add in the relation. - const toAdd = _.differenceWith(params.values[current], response[current], (a, b) => - a[this.primaryKey].toString() === b[this.primaryKey].toString() + const toAdd = _.differenceWith(params.values[current], response[current], (a, b) => + (a[this.primaryKey] || a).toString() === (b[this.primaryKey] || b).toString() ); // Records to remove in the relation. const toRemove = _.differenceWith(response[current], params.values[current], (a, b) => - a[this.primaryKey].toString() === b[this.primaryKey].toString() + (a[this.primaryKey] || a).toString() === (b[this.primaryKey] || b).toString() ) .filter(x => toAdd.find(y => x.id === y.id) === undefined);