mirror of
https://github.com/strapi/strapi.git
synced 2025-11-17 18:51:22 +00:00
Fix many-to-many relationships
This commit is contained in:
parent
90e2993e0d
commit
1df5709085
@ -34,19 +34,16 @@ class EditFormRelations extends React.Component { // eslint-disable-line react/p
|
|||||||
break;
|
break;
|
||||||
case 'oneToMany':
|
case 'oneToMany':
|
||||||
case 'manyToMany':
|
case 'manyToMany':
|
||||||
if (relation.dominant === true || relation.nature === 'manyToMany') {
|
return (
|
||||||
return (
|
<SelectMany
|
||||||
<SelectMany
|
currentModelName={this.props.currentModelName}
|
||||||
currentModelName={this.props.currentModelName}
|
key={i}
|
||||||
key={i}
|
record={this.props.record}
|
||||||
record={this.props.record}
|
relation={relation}
|
||||||
relation={relation}
|
schema={this.props.schema}
|
||||||
schema={this.props.schema}
|
setRecordAttribute={this.props.setRecordAttribute}
|
||||||
setRecordAttribute={this.props.setRecordAttribute}
|
/>
|
||||||
/>
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -127,7 +127,7 @@ module.exports = {
|
|||||||
|
|
||||||
// Push the work into the flow process.
|
// Push the work into the flow process.
|
||||||
toAdd.forEach(value => {
|
toAdd.forEach(value => {
|
||||||
value[details.via] = params.values[this.primaryKey];
|
value[details.via] = params.values[this.primaryKey] || params[this.primaryKey];
|
||||||
|
|
||||||
virtualFields.push(strapi.query(details.model || details.collection).addRelation({
|
virtualFields.push(strapi.query(details.model || details.collection).addRelation({
|
||||||
id: value[this.primaryKey] || value.id || value._id,
|
id: value[this.primaryKey] || value.id || value._id,
|
||||||
|
|||||||
@ -120,8 +120,10 @@ module.exports = {
|
|||||||
|
|
||||||
// Push the work into the flow process.
|
// Push the work into the flow process.
|
||||||
toAdd.forEach(value => {
|
toAdd.forEach(value => {
|
||||||
if (association.nature === 'manyToMany' && !_.isArray(params.values[this.primaryKey])) {
|
if (association.nature === 'manyToMany' && !_.isArray(params.values[this.primaryKey] || params[this.primaryKey])) {
|
||||||
value[details.via] = (value[details.via] || []).concat([params.values[this.primaryKey]]);
|
value[details.via] = (value[details.via] || []).concat([(params.values[this.primaryKey] || params[this.primaryKey])]).filter(x => {
|
||||||
|
return x !== null && x !== undefined;
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
value[details.via] = params[this.primaryKey] || params.id;
|
value[details.via] = params[this.primaryKey] || params.id;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user