From c570fd6ae386d07dbf6c53a100ac4133b8e8d377 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Thu, 29 Jan 2026 09:05:38 +0100 Subject: [PATCH] Refactor association keys in setupAssociations: Update foreign key naming conventions in Party and TitleOfNobility associations for consistency and clarity. Enhance error handling in FalukantService to ensure party ID is present before adding invited nobilities. --- backend/models/associations.js | 8 ++++---- backend/services/falukantService.js | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/models/associations.js b/backend/models/associations.js index d445af5..1f417aa 100644 --- a/backend/models/associations.js +++ b/backend/models/associations.js @@ -569,14 +569,14 @@ export default function setupAssociations() { Party.belongsToMany(TitleOfNobility, { through: PartyInvitedNobility, - foreignKey: 'party_id', - otherKey: 'title_of_nobility_id', + foreignKey: 'partyId', + otherKey: 'titleOfNobilityId', as: 'invitedNobilities', }); TitleOfNobility.belongsToMany(Party, { through: PartyInvitedNobility, - foreignKey: 'title_of_nobility_id', - otherKey: 'party_id', + foreignKey: 'titleOfNobilityId', + otherKey: 'partyId', as: 'partiesInvitedTo', }); diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index de1d370..e5bb5f4 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -3225,6 +3225,10 @@ class FalukantService extends BaseService { cost: cost }); if (nobilities.length > 0) { + // Stelle sicher, dass die Party eine ID hat + if (!party.id) { + throw new Error('Party wurde erstellt, hat aber keine ID'); + } // Verwende die bereits geladenen Objekte await party.addInvitedNobilities(nobilities); }