Search code examples
sails.jssails-mongo

how to return session users data only in sails.js?


I have a User model and user model has one to many relationship with Episode model. Is it possible to send only Episodes which are associated with the current user without changing the EpisodeController?


Solution

  • Yes. It is possible. you can use the concept of populate to do that.

    User.find({ criteria })
    .populate('episodes')
    .exec(function (err, user){
        // user.episodes should have episodes associated with a user.
    
    });