This is my User.model:
module.exports = {
attributes: {
name: {
type: 'string',
required: true,
minLength: 3,
maxLength: 30
},
username: {
type: 'string',
required: true,
},
toJSON: function() {
var obj = this.toObject();
obj.link = sails.config.globals.baseUrl + sails.config.routes.user + obj.id;
return obj;
}
}
};
I want to use some attribute that is "pre" designed for the model. My solution was to introduce attr in the toJSON () function, but in the views I should use:
<%= users.toJSON().link %>
Is there a way to create an attribute or some methods for the user? How:
module.exports = {
attributes: {
name: {
type: 'string',
required: true,
minLength: 3,
maxLength: 30
},
myPersonalAttribute: function(){
return "Value"
}
}
source
share