Sequelize版本:3.24.3
方言:MySQL
出于某种原因,当我打印出findById的结果时,我得到以下内容:
{ id: 1,
adminUserId: 16,
expiration: 2018-01-25T19:45:04.000Z,
admin_user_id: 16 }
我期待看到类似的东西
{ id: 1,
adminUserId: 16,
expiration: 2018-01-25T19:45:04.000Z }
没有重复的下划线ID。
这是我的模型定义:
module.exports = (sequelize, DataTypes) => {
const Device = sequelize.define('Device', {
id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
},
adminUserId: {
type: DataTypes.INTEGER,
field: 'admin_user_id',
},
expiration: DataTypes.DATE,
}, {
freezeTableName: true,
tableName: 'device',
timestamps: false,
classMethods: {
associate: function (model) {
Device.belongsTo(model.AdminUser, { foreignKey: { name: 'adminUserId', field: 'admin_user_id' } });
},
},
});
return Device;
};
答案 0 :(得分:0)
const db = Sequelize({
database: 'name_of_db',
dialect: 'mysql'
define: {
underscored: true
}