I'm trying to do the following:
// Task Model
module.exports = {
schema: true,
attributes: {
directProy: {
type: 'string',
required: true
},
user: {
type: 'string',
required: true
},
checkUser: {
type: 'boolean',
defaultsTo: false
},
proy: {
type: 'string',
required: true
},
pieza: {
type: 'string',
required: true
},
hours: {
type: 'string',
required: true
},
obs: {
type: 'text',
defaultsTo: "lorem ipsum"
},
check: {
type: 'boolean',
defaultsTo: false
},
userName: function() {
User.findOne(this.user).done(function(err, user){
if(err){ return err;}
return user.name;
});
}
}
};
In the method "userName" I'm trying to get the name of a user with the ID it stored in the "user" attribute.
but when I run the "username" method, brings me back "undefined", I think this has to be a problem of asynchronous type
Would greatly appreciate the help they can give me since I have no idea how to associate values between models and this is very useful