我正在使用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/