From 801c95bbc55b55c89b00f807e27c6d7dc249b75f Mon Sep 17 00:00:00 2001 From: fallenbagel <98979876+Fallenbagel@users.noreply.github.com> Date: Fri, 30 Jan 2026 00:54:05 +0800 Subject: [PATCH] fix: add explicit JoinClumn to MediaRequest media relation Fixes intermittent NULL mediaId foreign key on media_request records byadding explicit @JoinColumn decorator to the media relation. Without this,TypeORM's implicit FK mapping was unreliable, causing orphaned requeststhat would crash the frontend when accessing user profiles. Also removes the redundant @Column decorator for mediaId which conflicted withthe relation, and removes explicit mediaId assignments in the constructorwhich are now handled correctly by TypeORM through the relation. --- server/entity/MediaRequest.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/server/entity/MediaRequest.ts b/server/entity/MediaRequest.ts index 55f24fe5..00fb2b7e 100644 --- a/server/entity/MediaRequest.ts +++ b/server/entity/MediaRequest.ts @@ -21,6 +21,7 @@ import { AfterUpdate, Column, Entity, + JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn, @@ -341,7 +342,6 @@ export class MediaRequest { const request = new MediaRequest({ type: MediaType.MOVIE, media, - mediaId: media.id, requestedBy: requestUser, // If the user is an admin or has the "auto approve" permission, automatically approve the request status: user.hasPermission( @@ -458,7 +458,6 @@ export class MediaRequest { const request = new MediaRequest({ type: MediaType.TV, media, - mediaId: media.id, requestedBy: requestUser, // If the user is an admin or has the "auto approve" permission, automatically approve the request status: user.hasPermission( @@ -533,11 +532,9 @@ export class MediaRequest { eager: true, onDelete: 'CASCADE', }) + @JoinColumn({ name: 'mediaId' }) public media: Media; - @Column({ name: 'mediaId', nullable: true }) - public mediaId: number; - @ManyToOne(() => User, (user) => user.requests, { eager: true, onDelete: 'CASCADE',