I try to associate a chat message with an user. But the populate function gives me an user undefined
//message.js
module.exports = {
attributes: {
user:{
model: 'User'
},
message:{
type:'string',
required:true
}
}
};
I save an entry of a message and try to populate the messages with the user afterward
module.exports = {
test: function(req, res){
var data = {
user : "5533b9f00fe12ff020c67225",
message : 'auto generated'
};
Message.create(data, function messageCreated(err, message){
if(err) return res.negotiate(err);
Message.find().populate('user').exec(function(err, messages){
if(err) return res.negotiate(err);
res.json(messages);
});
});
}
};
But it always gives me user undefined
back, when I try to populate.
What I have tried so far:
- get one user and populate all his messages: works!
- find one user according the found Message's associated userId the step before, to ensure the user exists: works!
- change the Assosiation so another Message instead of an User and than populate the Messages with the one "master message" : works!
I don't understand why it works with other models but not the User model