I got 2 models, User and Friend. In friend i got 2 columns( UserId1, UserId2) I want to find in Friend rows where UserId1 is specified, and then from the table with these rows i want to return table with Users with Id = UserId2
index: function(req, res, next) {
Friend.find({UserId1 : req.session.User.id}, function foundUsers(err, friends) {
if (err) return next(err);
// pass the array down to the /views/index.ejs page
res.view({
friends: friends
});
});
}
This code above return table with Friends(UserId1, UserId2) where UserId1 is specified, but how to return table with Users (from model User) where Id = UserId2 ??