I have following model:
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,
}
});
I would like to create it like this while ignoring beforeUpdate/Create hooks:
User.create({ email: '[email protected]', role: 'admin', password: '############' },['email','password','role']).done(function(err,admin){ ... })
How?
You can do something like this:
return User.findOrCreate({
where: {email: "[email protected]"},
defaults: {
email: "[email protected]",
role: "admin",
password: "pyxBOZUNYNZCegyhthKCR9hWpgYO"
},
hooks: false //this will ignore hooks
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With