mirror of
https://github.com/strapi/strapi.git
synced 2025-11-03 11:25:17 +00:00
Merge pull request #2316 from strapi/fix/manyToMany
Allow array of IDs to manage relations through generated API
This commit is contained in:
commit
ec1e788469
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user