Refactor associations in models to include constraints: false, preventing automatic foreign key creation. Update sequelize.js to enhance foreign key management during model synchronization, ensuring associations are restored correctly after sync operations.

This commit is contained in:
Torsten Schulz (local)
2025-12-18 17:44:17 +01:00
parent c28f8b1384
commit 86f753c745
2 changed files with 96 additions and 16 deletions

View File

@@ -598,44 +598,52 @@ export default function setupAssociations() {
Learning.belongsTo(LearnRecipient, {
foreignKey: 'learningRecipientId',
as: 'recipient'
as: 'recipient',
constraints: false
}
);
LearnRecipient.hasMany(Learning, {
foreignKey: 'learningRecipientId',
as: 'learnings'
as: 'learnings',
constraints: false
});
Learning.belongsTo(FalukantUser, {
foreignKey: 'associatedFalukantUserId',
as: 'learner'
as: 'learner',
constraints: false
}
);
FalukantUser.hasMany(Learning, {
foreignKey: 'associatedFalukantUserId',
as: 'learnings'
as: 'learnings',
constraints: false
});
Learning.belongsTo(ProductType, {
foreignKey: 'productId',
as: 'productType'
as: 'productType',
constraints: false
});
ProductType.hasMany(Learning, {
foreignKey: 'productId',
as: 'learnings'
as: 'learnings',
constraints: false
});
Learning.belongsTo(FalukantCharacter, {
foreignKey: 'associatedLearningCharacterId',
as: 'learningCharacter'
as: 'learningCharacter',
constraints: false
});
FalukantCharacter.hasMany(Learning, {
foreignKey: 'associatedLearningCharacterId',
as: 'learningsCharacter'
as: 'learningsCharacter',
constraints: false
});
FalukantUser.hasMany(Credit, {