sot*_*isc 7 node.js sequelize.js
当Sequelize将实例保存到数据库(例如MySQL)时,它会自动在末尾添加"id"字段(也会自动增加).我已阅读文章和文档,但我找不到任何方法来禁用它.
谢谢.
Rob*_*sch 10
从源代码可以看出,如果将属性定义为"primaryKey",则DAO接口将删除默认的"id"字段,而不是您自己的主键.
请参阅dao-factory.js中的第1140行或附近:
var addDefaultAttributes = function() {
var self = this
, defaultAttributes = {
id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
}
}
if (this.hasPrimaryKeys) {
defaultAttributes = {}
}
... etc. ...
Run Code Online (Sandbox Code Playgroud)