gpt4 book ai didi

node.js - Nodejs - Sequelize hasMany 急切加载

转载 作者:太空宇宙 更新时间:2023-11-03 22:36:03 25 4
gpt4 key购买 nike

我正在使用sequelize最新版本,只是我需要在查找“Venue”模型时立即加载模型“VenueAddress”,但我收到以下错误:

感谢您的帮助。

TypeError: Cannot read property 'replace' of undefined
at Object.module.exports.removeTicks (d:\GitProjects\bashed\node_modules\sequelize\lib\utils.js:595:13)
at Object.module.exports.addTicks

//查找方法:

db.Venue.find({ where: {venueId: id},include: [{model: db.VenueAddress}]}).then(function(venue){
if(!venue) {
return next(new Error('Failed to load venue ' + id));
} else {
req.venue = venue;
return next();
}
}).catch(function(err){
return next(err);
});

//模型

Venue.hasMany(models.VenueAddress, {through: models.VenueAddress,foreignKey: 'venueId'});

VenueAddress.belongsTo(models.Venue, {through: models.VenueAddress,foreignKey: 'venueId'});

最佳答案

请引用以下链接: https://github.com/sequelize/sequelize/issues/3331#issuecomment-80886227

mickhansen said: Looks like you need to remove the through property from your Venue.hasMany association since it's not a N:M association.

关于node.js - Nodejs - Sequelize hasMany 急切加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29012998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com