iam*_*der 3 orm node.js sequelize.js
我在节点开发中将sequelize.js库用作ORM。当使用sequelize更新一行时,“ updated_at”字段更改为当前时间戳。我想知道如何防止这种情况?在不更改'updated_at'字段的情况下,我想使用sequlize API更新其他字段,而不运行原始查询。
小智 6
根据http://docs.sequelizejs.com/class/lib/model.js~Model.html#static-method-update,您可以使用“无提示”选项来运行更新查询,但不能更新updateAt字段。
options.silent布尔型
可选
默认值:false
如果为true,则不会更新UpdatedAt时间戳。
myModelInstance.update(values, {
silent: true
})
Run Code Online (Sandbox Code Playgroud)
在模型定义中,您可以关闭特定字段的时间戳。
如果您希望sequelize处理时间戳,但只想要其中的一些,或者希望您的时间戳被称为其他名称,您可以单独覆盖每一列:
var Foo = sequelize.define('foo', { /* bla */ }, {
// don't forget to enable timestamps!
timestamps: true,
// I don't want createdAt
createdAt: false,
// I want updatedAt to actually be called updateTimestamp
updatedAt: 'updateTimestamp'
// And deletedAt to be called destroyTime (remember to enable paranoid for this to work)
deletedAt: 'destroyTime',
paranoid: true
});
Run Code Online (Sandbox Code Playgroud)
否则,您可以关闭时间戳并根据需要在每次更新时手动处理它们。
| 归档时间: |
|
| 查看次数: |
1515 次 |
| 最近记录: |