Nodejs - sequelize hasMany eager loading

时间:2015-03-12 14:51:28

标签: node.js sequelize.js

我正在使用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'});

1 个答案:

答案 0 :(得分:0)

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

  米克汉森说:看起来你需要删除通过属性   来自你的Venue.hasMany协会,因为它不是N:M协会。