From 7f7886c5a704d6d19c07f57a588ae10a02b0d952 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 5 Dec 2021 19:32:31 +0100 Subject: [PATCH] docs(permissions): document why we can't lazy-load Signed-off-by: David Mehren --- src/permissions/note-group-permission.entity.ts | 7 +++++++ src/permissions/note-user-permission.entity.ts | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/permissions/note-group-permission.entity.ts b/src/permissions/note-group-permission.entity.ts index 2c0eb779b..52e18e662 100644 --- a/src/permissions/note-group-permission.entity.ts +++ b/src/permissions/note-group-permission.entity.ts @@ -10,6 +10,13 @@ import { Note } from '../notes/note.entity'; @Entity() export class NoteGroupPermission { + /** + * The `group` and `note` properties cannot be converted to promises + * (to lazy-load them), as TypeORM gets confused about lazy composite + * primary keys. + * See https://github.com/typeorm/typeorm/issues/6908 + */ + @ManyToOne((_) => Group, { primary: true, onDelete: 'CASCADE', // This deletes the NoteGroupPermission, when the associated Group is deleted diff --git a/src/permissions/note-user-permission.entity.ts b/src/permissions/note-user-permission.entity.ts index c0e128f9f..b60593a4b 100644 --- a/src/permissions/note-user-permission.entity.ts +++ b/src/permissions/note-user-permission.entity.ts @@ -10,6 +10,13 @@ import { User } from '../users/user.entity'; @Entity() export class NoteUserPermission { + /** + * The `user` and `note` properties cannot be converted to promises + * (to lazy-load them), as TypeORM gets confused about lazy composite + * primary keys. + * See https://github.com/typeorm/typeorm/issues/6908 + */ + @ManyToOne((_) => User, { primary: true, onDelete: 'CASCADE', // This deletes the NoteUserPermission, when the associated Note is deleted