vendredi 3 avril 2015

SailsJs beforeCreate method receives only the model properties on which required is set to true

This is a model in sails.js.



module.exports = {

attributes: {
name: {
type: "string"
},
email: {
type: "email",
required: true
},
password: {
type: "string"
}
},

beforeCreate: function(values, next) {
console.log(values); //logs {email:"mail@someplace.com"}
console.log(values.email); // logs the email id sent via post
console.log(values.password); // logs undefined is required is set to false, If required is set to true, password will log properly.
next();
}
};


I am planning to perform some encrypting of the password in the beforeCreate function, Of course I will be requiring the password and can continue with it right now but how to manage this for optional values just in case the need arises?


Aucun commentaire:

Enregistrer un commentaire