Relationships controllers

This commit is contained in:
2025-04-17 23:54:35 +08:00
parent cec8c3af81
commit f9701764f3
8 changed files with 282 additions and 61 deletions

View File

@ -53,15 +53,15 @@ public class AppDatabase(
.HasForeignKey<Account.Profile>(p => p.Id);
modelBuilder.Entity<Account.Relationship>()
.HasKey(r => new { r.FromAccountId, r.ToAccountId });
.HasKey(r => new { FromAccountId = r.AccountId, ToAccountId = r.RelatedId });
modelBuilder.Entity<Account.Relationship>()
.HasOne(r => r.FromAccount)
.HasOne(r => r.Account)
.WithMany(a => a.OutgoingRelationships)
.HasForeignKey(r => r.FromAccountId);
.HasForeignKey(r => r.AccountId);
modelBuilder.Entity<Account.Relationship>()
.HasOne(r => r.ToAccount)
.HasOne(r => r.Related)
.WithMany(a => a.IncomingRelationships)
.HasForeignKey(r => r.ToAccountId);
.HasForeignKey(r => r.RelatedId);
// Automatically apply soft-delete filter to all entities inheriting BaseModel
foreach (var entityType in modelBuilder.Model.GetEntityTypes())