mirror of
https://github.com/strapi/strapi.git
synced 2025-09-27 17:29:14 +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(
|
virtualFields.push(
|
||||||
model.findOne({
|
module.exports.addRelation.call(model, {
|
||||||
[model.primaryKey]: getValuePrimaryKey(value, model.primaryKey)
|
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