Fix many-to-many relationships

This commit is contained in:
Aurelsicoko 2017-10-23 17:35:00 +02:00
parent 90e2993e0d
commit 1df5709085
3 changed files with 15 additions and 16 deletions

View File

@ -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;
}

View File

@ -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,

View File

@ -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;
}