mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 08:19:07 +00:00
fix(relations): avoid duplicate entries in manyToMany relations
This commit is contained in:
parent
8e393492d2
commit
cca35fe9ac
@ -124,22 +124,11 @@ module.exports = {
|
||||
}
|
||||
|
||||
virtualFields.push(
|
||||
model.findOne({
|
||||
[model.primaryKey]: getValuePrimaryKey(value, model.primaryKey)
|
||||
module.exports.addRelation.call(model, {
|
||||
id: getValuePrimaryKey(value, this.primaryKey),
|
||||
values: _.pick(value, [this.primaryKey, details.via]),
|
||||
foreignKey: current
|
||||
})
|
||||
.populate([details.via])
|
||||
.lean()
|
||||
.then(entry => {
|
||||
if (_.isArray(entry[details.via])) {
|
||||
value[details.via] = entry[details.via].map(entry => _.get(entry, '_id', entry)).concat(value[details.via]);
|
||||
}
|
||||
|
||||
return module.exports.addRelation.call(model, {
|
||||
id: getValuePrimaryKey(value, this.primaryKey),
|
||||
values: _.pick(value, [this.primaryKey, details.via]),
|
||||
foreignKey: current
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user