带下划线的模型配置似乎会影响与相应表列关联的每个属性。是否有方法重写模型级配置,以便与表列关联的属性保留表的原始列名?
代码示例:
const someModel = sequelize.define('some_table', {
'id': {
type: dataTypes.BIGINT,
primaryKey: true,
autoIncrement: true,
},
'other_table_id': {
type: dataTypes.BIGINT,
allowNull: false,
references: {
model: 'other_table',
key: 'id',
deferrable: INITIALLY_IMMEDIATE,
},
},
'CAPITAL_letterColumn': {
type: dataTypes.STRING,
allowNull: true,
defaultValue: null,,
}
}, {
timestamps: false,
paranoid: false,
// underscored: true, // true === snake case, false === camelcase
}
});
someModel.associate = (models) => {
someModel.belongsTo(models.other_table, { foreignKey: 'other_table_id', targetKey: 'id' });
};
我得到以下错误:
UnhandledPromiseRejectionWarning: SequelizeDatabaseError: column "otherTableId" does not exist
如果我设置
underscored: true
我得到以下错误:
UnhandledPromiseRejectionWarning: SequelizeDatabaseError: column "c_a_p_i_t_a_l_letter_column" of relation "some_table" does not exist