更新时间:2023-01-29 08:41:55
通过在 sequelize 的单例模块中编写几行代码,我自己解决了问题:
Resolved the problem at my own by writing the few lines of code in my singleton module of sequelize:
Object.keys(db).forEach(function(modelName) {
if(db[modelName].hasOwnProperty('associate')) {
db[modelName].associate(db);
}
});
代码将遍历所有模型并直接调用它们的关联方法,因为它们已被定义为 classMethods.
The code will iterate over all the models and call their associate methods directly as they have been defined as classMethods.