Merge pull request #1342 from strapi/fix-1269

Fix bug when deleting a relation that has the same field on both sides
This commit is contained in:
Jim LAURIE 2018-06-11 17:59:35 +02:00 committed by GitHub
commit e62c7c2a11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -144,6 +144,7 @@ InputSelectWithErrors.defaultProps = {
labelStyle: {},
onBlur: false,
onFocus: () => {},
selectOptions: [],
style: {},
tabIndex: '0',
validations: {},
@ -198,7 +199,7 @@ InputSelectWithErrors.propTypes = {
}),
PropTypes.string,
]),
).isRequired,
),
style: PropTypes.object,
tabIndex: PropTypes.string,
validations: PropTypes.object,

View File

@ -146,9 +146,12 @@ export class ModelPage extends React.Component { // eslint-disable-line react/pr
}
handleDelete = (attributeName) => {
const index = findIndex(this.props.modelPage.model.attributes, ['name', attributeName]);
const parallelAttributeIndex = findIndex(this.props.modelPage.model.attributes, (attr) => attr.params.key === attributeName);
const { modelPage: { model } } = this.props;
const index = findIndex(model.attributes, ['name', attributeName]);
const attributeToRemove = get(model, ['attributes', index]);
const parallelAttributeIndex = attributeToRemove.name === attributeToRemove.params.key ?
-1 : findIndex(model.attributes, (attr) => attr.params.key === attributeName);
this.props.deleteAttribute(index, this.props.match.params.modelName, parallelAttributeIndex !== -1);
}