From 3e096e9cbee4c468b86a36cf7e96744f82a481d7 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 13 Mar 2022 20:23:27 +0100 Subject: [PATCH] fix(note-user-permission): ensure whole row gets deleted By default, TypeORM wants to NULL the child-side of a many-to-one relation, when the relation gets deleted. This is not possible when the column is not nullable, so the whole row needs to get deleted. Signed-off-by: David Mehren --- src/permissions/note-user-permission.entity.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/permissions/note-user-permission.entity.ts b/src/permissions/note-user-permission.entity.ts index b60593a4b..4f73bd6b4 100644 --- a/src/permissions/note-user-permission.entity.ts +++ b/src/permissions/note-user-permission.entity.ts @@ -20,12 +20,14 @@ export class NoteUserPermission { @ManyToOne((_) => User, { primary: true, onDelete: 'CASCADE', // This deletes the NoteUserPermission, when the associated Note is deleted + orphanedRowAction: 'delete', // This ensures the whole row is deleted when the Permission stops being referenced }) user: User; @ManyToOne((_) => Note, (note) => note.userPermissions, { primary: true, onDelete: 'CASCADE', // This deletes the NoteUserPermission, when the associated Note is deleted + orphanedRowAction: 'delete', // This ensures the whole row is deleted when the Permission stops being referenced }) note: Note;