diff --git a/src/notes/note.entity.ts b/src/notes/note.entity.ts index 1adcef9cb..538af568b 100644 --- a/src/notes/note.entity.ts +++ b/src/notes/note.entity.ts @@ -39,9 +39,14 @@ export class Note { @OneToMany( (_) => NoteGroupPermission, (groupPermission) => groupPermission.note, + { cascade: true }, // This ensures that embedded NoteGroupPermissions are automatically saved to the database ) groupPermissions: NoteGroupPermission[]; - @OneToMany((_) => NoteUserPermission, (userPermission) => userPermission.note) + @OneToMany( + (_) => NoteUserPermission, + (userPermission) => userPermission.note, + { cascade: true }, // This ensures that embedded NoteUserPermission are automatically saved to the database + ) userPermissions: NoteUserPermission[]; @Column({ nullable: false, diff --git a/src/permissions/note-group-permission.entity.ts b/src/permissions/note-group-permission.entity.ts index d1e94112c..364c2991d 100644 --- a/src/permissions/note-group-permission.entity.ts +++ b/src/permissions/note-group-permission.entity.ts @@ -10,10 +10,16 @@ import { Note } from '../notes/note.entity'; @Entity() export class NoteGroupPermission { - @ManyToOne((_) => Group, { primary: true }) + @ManyToOne((_) => Group, { + primary: true, + onDelete: 'CASCADE', // This deletes the NoteGroupPermission, when the associated Group is deleted + }) group: Group; - @ManyToOne((_) => Note, (note) => note.groupPermissions, { primary: true }) + @ManyToOne((_) => Note, (note) => note.groupPermissions, { + primary: true, + onDelete: 'CASCADE', // This deletes the NoteGroupPermission, when the associated Note is deleted + }) note: Note; @Column() diff --git a/src/permissions/note-user-permission.entity.ts b/src/permissions/note-user-permission.entity.ts index 0bad0d41d..06e94d0af 100644 --- a/src/permissions/note-user-permission.entity.ts +++ b/src/permissions/note-user-permission.entity.ts @@ -10,10 +10,16 @@ import { User } from '../users/user.entity'; @Entity() export class NoteUserPermission { - @ManyToOne((_) => User, { primary: true }) + @ManyToOne((_) => User, { + primary: true, + onDelete: 'CASCADE', // This deletes the NoteUserPermission, when the associated Note is deleted + }) user: User; - @ManyToOne((_) => Note, (note) => note.userPermissions, { primary: true }) + @ManyToOne((_) => Note, (note) => note.userPermissions, { + primary: true, + onDelete: 'CASCADE', // This deletes the NoteUserPermission, when the associated Note is deleted + }) note: Note; @Column()