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,7 +34,6 @@ 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}
@ -45,8 +44,6 @@ class EditFormRelations extends React.Component { // eslint-disable-line react/p
setRecordAttribute={this.props.setRecordAttribute} setRecordAttribute={this.props.setRecordAttribute}
/> />
); );
}
break;
default: default:
break; break;
} }

View File

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

View File

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