I have model User
. To simplify my issue it has not attributes (except id that is produced by sails engine):
module.exports = {
}
I have also model UserPost
:
module.exports = {
attributes: {
user: {
required: true,
model: 'user'
}
}
}
I want to find posts of user with id equal to 42. I have that records in database, both user with id 42, and its posts.
This doesn't work:
UserPost.find().populate('user', {
id: 42
}).exec(function(err, posts) {
res.json(posts);
});
Of course, in this case I can just pass query criteria to find()
. Anyway in general I should be able to find not only by id but the other attributes too.
How can I do that?