You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A `onSoftDeleteCascade("children") for a soft-deleted to soft-delete its owned children
A `onSoftDeleteUnset("projectItem") for a soft-deleted entity to unhook itself from other entities
Examples
Cascade to soft-deleted children & on soft-delete cascade a hard deletion to other children:
/** Cascade cascade soft deletes to dependencies. */// TODO(soft-deleted): https://github.com/stephenh/joist-ts/issues/910config.beforeFlush(["requiredTaskDocuments","scheduleTaskChecklistItems"],async(task,{ em })=>{if(task.isSoftDeletedEntity&&task.changes.deletedAt.hasChanged){constdependencies=(awaitPromise.all([task.successorDependencies.load(),task.predecessorDependencies.load()])).flat();dependencies.forEach((d)=>d.softDelete());task.requiredTaskDocuments.get.forEach((rtd)=>em.delete(rtd));task.scheduleTaskChecklistItems.get.forEach((stci)=>em.delete(stci));}});
/** On task soft-delete, unhook any project items. */// TODO(soft-deleted): https://github.com/stephenh/joist-ts/issues/910config.beforeFlush(async(task)=>{if(task.isSoftDeletedEntity){constprojectItems=awaittask.load((t)=>t.projectItems);projectItems.forEach((pi)=>pi.task.set(undefined));}});
Maybe prevent soft deletion?
/** Tasks on a draw schedule, or a global milestone, cannot be soft-deleted. */
config.addRule(async (task) => {
if (task.isSoftDeletedEntity) {
const draws = await task.load((t) => t.homeownerContractDraws);
if (draws.length > 0) {
return "Cannot delete tasks on a draw schedule";
}
if (!task.allowMilestoneDelete && (await task.isGlobalMilestoneTask())) {
return "Milestone tasks cannot be deleted";
}
}
});
The text was updated successfully, but these errors were encountered:
stephenh
changed the title
Enforce soft-deleted entities being hooked
Enforce soft-deleted entities are unhooked
Dec 13, 2023
And in general ergonomics like:
Examples
Cascade to soft-deleted children & on soft-delete cascade a hard deletion to other children:
Maybe prevent soft deletion?
The text was updated successfully, but these errors were encountered: