mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 08:52:26 +00:00
filter empty components when deleting entity
This commit is contained in:
parent
2042d6beb0
commit
cf67b12b3f
@ -214,10 +214,14 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const componentsToDelete = await getComponents(uid, entityToDelete);
|
const componentsToDelete = await getComponents(uid, entityToDelete).then((x) =>
|
||||||
|
_.omitBy(_.isNill, x)
|
||||||
|
);
|
||||||
|
|
||||||
await db.query(uid).delete({ where: { id: entityToDelete.id } });
|
await db.query(uid).delete({ where: { id: entityToDelete.id } });
|
||||||
|
if (!_.isEmpty(componentsToDelete)) {
|
||||||
await deleteComponents(uid, { ...entityToDelete, ...componentsToDelete });
|
await deleteComponents(uid, { ...entityToDelete, ...componentsToDelete });
|
||||||
|
}
|
||||||
|
|
||||||
await this.emitEvent(uid, ENTRY_DELETE, entityToDelete);
|
await this.emitEvent(uid, ENTRY_DELETE, entityToDelete);
|
||||||
|
|
||||||
@ -238,11 +242,15 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
|
|||||||
}
|
}
|
||||||
|
|
||||||
const componentsToDelete = await Promise.all(
|
const componentsToDelete = await Promise.all(
|
||||||
entitiesToDelete.map((entityToDelete) => getComponents(uid, entityToDelete))
|
entitiesToDelete.map((entityToDelete) =>
|
||||||
|
getComponents(uid, entityToDelete).then((x) => _.omitBy(_.isNill, x))
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const deletedEntities = await db.query(uid).deleteMany(query);
|
const deletedEntities = await db.query(uid).deleteMany(query);
|
||||||
await Promise.all(componentsToDelete.map((compos) => deleteComponents(uid, compos)));
|
await Promise.all(
|
||||||
|
componentsToDelete.map((compos) => !_.isEmpty(compos) && deleteComponents(uid, compos))
|
||||||
|
);
|
||||||
|
|
||||||
// Trigger webhooks. One for each entity
|
// Trigger webhooks. One for each entity
|
||||||
await Promise.all(entitiesToDelete.map((entity) => this.emitEvent(uid, ENTRY_DELETE, entity)));
|
await Promise.all(entitiesToDelete.map((entity) => this.emitEvent(uid, ENTRY_DELETE, entity)));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user