下划线被删除

Sequelize删除我的外键中的下划线。

Role.belongsToMany(User, { foreignKey: 'user_id', through: UserRole });

结果在这:

Unknown column 'UserRole.UserId' in 'field list'

因为该列名为user_id,而不是UserId。

即使是underscore: true选项设置,它是这样做的。

有没有办法解决这个问题,这是让我疯狂,因为,我不知道我是否做错了或续集。

UserRole.js:

 module.exports = { attributes: { roleId: { type: Sequelize.INTEGER(11), field: 'role_id', primaryKey: true }, userId: { type: Sequelize.INTEGER(11), field: 'user_id', primaryKey: true } }, associations: function() { UserRole.belongsTo(User, { foreignKey: 'user_id' }); UserRole.hasOne(Role, { foreignKey: 'id' }); }, options: { tableName: 'user_roles', timestamps: false, classMethods: {}, instanceMethods: {}, hooks: {} } } 

Role.js

 module.exports = { attributes: { id: { type: Sequelize.INTEGER(11), primaryKey: true }, name: { type: Sequelize.STRING(50), }, description: { type: Sequelize.STRING(50), }, }, associations: function() { Role.belongsToMany(User, { foreignKey: 'user_id', through: UserRole }); }, options: { tableName: 'roles', timestamps: false, classMethods: {}, instanceMethods: {}, hooks: {} } } 

       

网上收集的解决方案 "下划线被删除"