Reputation: 13164
Is there a way to set one attribute equal to the other in sails.js model before it is not updated? Something like:
username: {
type: 'string',
required: true
},
fullname: {
type: 'string',
defaultsTo: this.username
},
...
Upvotes: 0
Views: 132
Reputation: 5979
Yes you can do this using a afterValidate callback. I reccomend afterValidate() because it will have checked for the already required username.
attributes : {
username: {type:'string',required:true},
fullname: {type:'string'}
},
afterValidate: function(values,next){
if(!values.fullname) values.fullname = values.username;
return next();
}
Upvotes: 1