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.
This commit is contained in:
@@ -569,14 +569,14 @@ export default function setupAssociations() {
|
|||||||
|
|
||||||
Party.belongsToMany(TitleOfNobility, {
|
Party.belongsToMany(TitleOfNobility, {
|
||||||
through: PartyInvitedNobility,
|
through: PartyInvitedNobility,
|
||||||
foreignKey: 'party_id',
|
foreignKey: 'partyId',
|
||||||
otherKey: 'title_of_nobility_id',
|
otherKey: 'titleOfNobilityId',
|
||||||
as: 'invitedNobilities',
|
as: 'invitedNobilities',
|
||||||
});
|
});
|
||||||
TitleOfNobility.belongsToMany(Party, {
|
TitleOfNobility.belongsToMany(Party, {
|
||||||
through: PartyInvitedNobility,
|
through: PartyInvitedNobility,
|
||||||
foreignKey: 'title_of_nobility_id',
|
foreignKey: 'titleOfNobilityId',
|
||||||
otherKey: 'party_id',
|
otherKey: 'partyId',
|
||||||
as: 'partiesInvitedTo',
|
as: 'partiesInvitedTo',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3225,6 +3225,10 @@ class FalukantService extends BaseService {
|
|||||||
cost: cost
|
cost: cost
|
||||||
});
|
});
|
||||||
if (nobilities.length > 0) {
|
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
|
// Verwende die bereits geladenen Objekte
|
||||||
await party.addInvitedNobilities(nobilities);
|
await party.addInvitedNobilities(nobilities);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user