According to the documentation Custom Attribute Methods can be defined on the model, and then later used on objects returned from Queries made through Waterline, Sails JS's ORM.
This is not working for me. I am getting the correct data back from the query but none of functions that I declare on the model work. Trying to call them results in a TypeError: Object [object Object] has no method 'methodName'
(Update with a clearer example)
Here is my Model with the custom Attribute method
module.exports = {
attributes: {
firstName : {
type: 'string'
},
lastName : {
type: 'string'
}
},
// Custom Attribute Method
fullName : function(){
return this.firstName + " " + this.lastName
}
};
Here is where I am using it in the controller
module.exports = {
findMe: function(req, res){
User.findOne({firstName:'Todd'}).exec(function(err, user){
console.log(user.fullName()); //<--TypeError: Object [object Object] has no method 'fullName'
res.send(user);
})
}
};
What am I missing?