-
Notifications
You must be signed in to change notification settings - Fork 369
Closed
Labels
Description
Hi,
Thanks a lot for this project. I was wondering if I'm doing something wrong here—I expect to be able to modify the properties of a model in beforeCreate, but Postgres shows the following in the database:
id | email | password | salt | created
----+---------------------+----------+------+---------
1 | test@email.com | visible? | |
var orm = require('orm'),
bcrypt = require('bcrypt');
orm.connect('postgres://localhost/database', function (err, db) {
var Person = db.define('Person', {
email: String,
password: String,
salt: String,
created: Date
}, {
validations: {
email: orm.validators.unique()
},
hooks: {
beforeCreate: function () {
if (!this.salt) {
console.log('Generating salt...');
this.salt = bcrypt.genSaltSync(10);
this.created = new Date();
}
if (this.password) {
console.log('Hashing password...');
this.password = bcrypt.hashSync(this.password, this.salt);
}
}
}
});
// Person.sync(function (err) { console.log(err); });
Person.create([{
email: 'test@email.com',
password: 'visible?'
}], function (err, items) {
console.log(err);
// console.log(items);
});
});Testing with beforeSave yields different results for me, too: the password gets hashed, but salt and created go unset in the database.
Reactions are currently unavailable