1602/express-on-railway — Issue #77: How to avoid unwanted feilds to be saved to database
Author: cayasso
Created: 2011-12-11 07:41:09+00:00
State: open

How to avoided unwanted fields (not declared in schema) to be saved to my database, for example, authenticity_token or password.

An another question: In previous version of railway when using mongoose I used to do define a virtual and a setter to save my password (instead of password, salt and hash was saved to my DB)

User.virtual('password')
.get(function(){
return this._password;
})
.set(function(password) {
this._password = password;
var salt = this.salt = bcrypt.gen_salt_sync(10);
this.hash = bcrypt.encrypt_sync(password, salt);
});

What would be the equivalent of doing so with the new way of defining schemas, I tried to use beforeCreate and beforeSave but those methods doesnt have access to the req.body.password from the form, so I have no idea, is there an easy way to do this in schema or I would need to force it in the Controller?.

Thanks!

JB