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'
})
4条答案
按热度按时间p4tfgftt1#
文档说明您可以使用属性
freezeTableName
。请看这个例子:
x33g5p2x2#
虽然接受的答案是正确的,但您可以对所有表执行一次此操作,而不必对每个表单独执行此操作。你只需将一个类似的options对象传入Sequelize构造函数,如下所示:
现在,当你定义实体时,你不必指定
freezeTableName: true
:kcwpcxri3#
您可以直接执行它,而不是像下面这样在每个表中指定一次
或
你也可以直接告诉Sequelize表的名字:
你可以在sequelize.js的文档中看到这两种方法
freezeTableName
相关sequelize.js文档ztmd8pv54#
如果你需要为单数和复数定义使用不同的模型名称,你可以在模型的选项中传递name作为参数。
请看这个例子:
当查询单个记录时,这将返回“person”作为对象,当我们获取多个记录时,返回“people”作为数组。