Fix delete on Mongoose

This commit is contained in:
Aurelsicoko 2017-09-20 18:14:18 +02:00
parent bd16913b02
commit cefaff4c45
4 changed files with 8 additions and 5 deletions

View File

@ -142,6 +142,7 @@ export class Edit extends React.Component {
if (isEmpty(formErrors)) { if (isEmpty(formErrors)) {
this.props.editRecord(); this.props.editRecord();
if (!isEmpty(this.props.location.search)) { if (!isEmpty(this.props.location.search)) {
router.push(replace(this.props.location.search, '?redirectUrl=', '')); router.push(replace(this.props.location.search, '?redirectUrl=', ''));
} else { } else {

View File

@ -190,7 +190,7 @@ export class List extends React.Component {
history={this.props.history} history={this.props.history}
primaryKey={currentModel.primaryKey || 'id'} primaryKey={currentModel.primaryKey || 'id'}
handleDelete={this.toggleModalWarning} handleDelete={this.toggleModalWarning}
redirectUrl={`?redirectUrl=/plugins/content-manager/category/?page=${this.props.currentPage}&limit=${this.props.limit}&sort=${this.props.sort}`} redirectUrl={`?redirectUrl=/plugins/content-manager/${this.props.currentModelName.toLowerCase()}/?page=${this.props.currentPage}&limit=${this.props.limit}&sort=${this.props.sort}`}
/> />
); );
} }

View File

@ -175,7 +175,7 @@ module.exports = {
// Delete entry. // Delete entry.
return this return this
.remove({ .remove({
[this.primaryKey]: params[this.primaryKey] || params._id [this.primaryKey]: params.id
}); });
}, },

View File

@ -87,7 +87,7 @@ module.exports = {
const params = ctx.params; const params = ctx.params;
const response = await strapi.query(params.model).findOne({ const response = await strapi.query(params.model).findOne({
id: params.id id: params.id
}) });
params.values = Object.keys(JSON.parse(JSON.stringify(response))).reduce((acc, current) => { params.values = Object.keys(JSON.parse(JSON.stringify(response))).reduce((acc, current) => {
const association = strapi.models[params.model].associations.filter(x => x.alias === current)[0]; const association = strapi.models[params.model].associations.filter(x => x.alias === current)[0];
@ -100,8 +100,10 @@ module.exports = {
return acc; return acc;
}, {}); }, {});
if (!_.isEmpty(params.values)) {
// Run update to remove all relationships. // Run update to remove all relationships.
await strapi.query(params.model).update(params); await strapi.query(params.model).update(params);
}
// Delete an entry using `queries` system // Delete an entry using `queries` system
const entryDeleted = await strapi.query(params.model).delete({ const entryDeleted = await strapi.query(params.model).delete({