Merge pull request #2316 from strapi/fix/manyToMany

Allow array of IDs to manage relations through generated API
This commit is contained in:
Jim LAURIE 2018-11-18 14:16:36 +01:00 committed by GitHub
commit ec1e788469
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -97,13 +97,13 @@ module.exports = {
acc[current] = params.values[current]; acc[current] = params.values[current];
} else if (response[current] && _.isArray(response[current]) && current !== 'id') { } else if (response[current] && _.isArray(response[current]) && current !== 'id') {
// Records to add in the relation. // Records to add in the relation.
const toAdd = _.differenceWith(params.values[current], response[current], (a, b) => const toAdd = _.differenceWith(params.values[current], response[current], (a, b) =>
a[this.primaryKey].toString() === b[this.primaryKey].toString() (a[this.primaryKey] || a).toString() === (b[this.primaryKey] || b).toString()
); );
// Records to remove in the relation. // Records to remove in the relation.
const toRemove = _.differenceWith(response[current], params.values[current], (a, b) => 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); .filter(x => toAdd.find(y => x.id === y.id) === undefined);