本文介绍了如何使Sequelize使用单表名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为User的模型,但是每当我尝试保存在数据库中时,Sequelize都会查找表USERS.有人知道如何将Sequelize设置为使用单表名称吗?谢谢.
I have an model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.
推荐答案
文档指出可以使用属性freezeTableName
.
请查看以下示例:
var Bar = sequelize.define('Bar', { /* bla */ }, {
// don't add the timestamp attributes (updatedAt, createdAt)
timestamps: false,
// don't delete database entries but set the newly added attribute deletedAt
// to the current date (when deletion was done). paranoid will only work if
// timestamps are enabled
paranoid: true,
// don't use camelcase for automatically added attributes but underscore style
// so updatedAt will be updated_at
underscored: true,
// disable the modification of tablenames; By default, sequelize will automatically
// transform all passed model names (first parameter of define) into plural.
// if you don't want that, set the following
freezeTableName: true,
// define the table's name
tableName: 'my_very_custom_table_name'
})
这篇关于如何使Sequelize使用单表名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!