mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +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;
|
||||
case 'oneToMany':
|
||||
case 'manyToMany':
|
||||
if (relation.dominant === true || relation.nature === 'manyToMany') {
|
||||
return (
|
||||
<SelectMany
|
||||
currentModelName={this.props.currentModelName}
|
||||
key={i}
|
||||
record={this.props.record}
|
||||
relation={relation}
|
||||
schema={this.props.schema}
|
||||
setRecordAttribute={this.props.setRecordAttribute}
|
||||
/>
|
||||
);
|
||||
}
|
||||
break;
|
||||
return (
|
||||
<SelectMany
|
||||
currentModelName={this.props.currentModelName}
|
||||
key={i}
|
||||
record={this.props.record}
|
||||
relation={relation}
|
||||
schema={this.props.schema}
|
||||
setRecordAttribute={this.props.setRecordAttribute}
|
||||
/>
|
||||
);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ module.exports = {
|
||||
|
||||
// Push the work into the flow process.
|
||||
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({
|
||||
id: value[this.primaryKey] || value.id || value._id,
|
||||
|
||||
@ -120,8 +120,10 @@ module.exports = {
|
||||
|
||||
// Push the work into the flow process.
|
||||
toAdd.forEach(value => {
|
||||
if (association.nature === 'manyToMany' && !_.isArray(params.values[this.primaryKey])) {
|
||||
value[details.via] = (value[details.via] || []).concat([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] || params[this.primaryKey])]).filter(x => {
|
||||
return x !== null && x !== undefined;
|
||||
});
|
||||
} else {
|
||||
value[details.via] = params[this.primaryKey] || params.id;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user