From 10448211471631bedf8a65dbd33d9b801f62f885 Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 16 Dec 2024 20:03:38 +0100 Subject: [PATCH] Fix relation Manga->Chapter (latest) --- API/Schema/Chapter.cs | 1 - API/Schema/Manga.cs | 3 +++ API/Schema/PgsqlContext.cs | 25 +++++++++++-------------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/API/Schema/Chapter.cs b/API/Schema/Chapter.cs index b398152..2de4f19 100644 --- a/API/Schema/Chapter.cs +++ b/API/Schema/Chapter.cs @@ -18,7 +18,6 @@ public class Chapter : IComparable public string ArchiveFileName { get; private set; } public bool Downloaded { get; internal set; } = false; - [ForeignKey("MangaId")] public Manga ParentManga { get; init; } public Chapter(Manga parentManga, string url, float chapterNumber, diff --git a/API/Schema/Manga.cs b/API/Schema/Manga.cs index a33d3cf..c87b15c 100644 --- a/API/Schema/Manga.cs +++ b/API/Schema/Manga.cs @@ -46,10 +46,13 @@ public class Manga( public string FolderName { get; private set; } = BuildFolderName(name); public float IgnoreChapterBefore { get; internal set; } = ignoreChapterBefore; + [ForeignKey("LatestChapterDownloadedId")] public Chapter? LatestChapterDownloaded { get; private set; } = latestChapterDownloaded; + [ForeignKey("LatestChapterAvailableId")] public Chapter? LatestChapterAvailable { get; private set; } = latestChapterAvailable; + [ForeignKey("MangaConnectorId")] public MangaConnector MangaConnector { get; private set; } = mangaConnector; [ForeignKey("AuthorIds")] diff --git a/API/Schema/PgsqlContext.cs b/API/Schema/PgsqlContext.cs index e4442e6..4b952e4 100644 --- a/API/Schema/PgsqlContext.cs +++ b/API/Schema/PgsqlContext.cs @@ -51,18 +51,6 @@ public class PgsqlContext(DbContextOptions options) : DbContext(op .HasValue(JobType.DownloadSingleChapterJob) .HasValue(JobType.UpdateMetaDataJob); - modelBuilder.Entity() - .HasOne(c => c.ParentManga); - modelBuilder.Entity() - .Navigation(c => c.ParentManga) - .AutoInclude(); - - modelBuilder.Entity() - .HasOne(m => m.LatestChapterAvailable) - .WithOne(); - modelBuilder.Entity() - .HasOne(m => m.LatestChapterDownloaded) - .WithOne(); modelBuilder.Entity() .HasOne(m => m.MangaConnector); modelBuilder.Entity() @@ -79,14 +67,23 @@ public class PgsqlContext(DbContextOptions options) : DbContext(op .Navigation(m => m.Tags) .AutoInclude(); modelBuilder.Entity() - .HasMany(m => m.Links); + .HasMany(m => m.Links) + .WithOne(); modelBuilder.Entity() .Navigation(m => m.Links) .AutoInclude(); modelBuilder.Entity() - .HasMany(m => m.AltTitles); + .HasMany(m => m.AltTitles) + .WithOne(); modelBuilder.Entity() .Navigation(m => m.AltTitles) .AutoInclude(); + + modelBuilder.Entity() + .HasOne(c => c.ParentManga) + .WithMany(); + modelBuilder.Entity() + .Navigation(c => c.ParentManga) + .AutoInclude(); } } \ No newline at end of file