gpt4 book ai didi

sequelize.js - 如何忽略钩子(Hook)?

转载 作者:行者123 更新时间:2023-12-04 21:43:23 24 4
gpt4 key购买 nike

我有以下模型:

sequelize.define("User", {
id: {
type: DataTypes.INTEGER(11),
autoIncrement: true,
primaryKey: true
},
email: {
type: DataTypes.STRING(255),
allowNull: false,
unique: true,
},
password: {
type: DataTypes.STRING(60),
allowNull: false
},
role: {
type: DataTypes.STRING(32),
allowNull: false,
defaultValue: 'user',
}
},{

instanceMethods: {
verifyPassword: function(password,cb) {
crypt.compare(password,this.password,cb);
},
},

hooks: {
beforeUpdate: hashPassword,
beforeCreate: hashPassword,
}

});

我想这样创建它,同时忽略 beforeUpdate/Create 钩子(Hook):
User.create({ email: 'admin@render.ly', role: 'admin', password: '############' },['email','password','role']).done(function(err,admin){ ... })

如何?

最佳答案

你可以这样做:

return User.findOrCreate({
where: {email: "admin@render.ly"},
defaults: {
email: "admin@render.ly",
role: "admin",
password: "pyxBOZUNYNZCegyhthKCR9hWpgYO"
},
hooks: false //this will ignore hooks
})

关于sequelize.js - 如何忽略钩子(Hook)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20707199/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com