下划线被删除

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: {} } } 

它看起来不像在模型中启用了underscore选项。 如果设置Sequelize尊重你的命名约定偏好,并将按预期连接起来。

我更喜欢下划线的名字,很长一段时间的Rails开发者,以及混合大小写的列名称,这些名字的结果看起来很糟糕。