Sails.js request for waterline association

In sails.js I have a Post model with many-to-many relationship with another model "tag"

MODEL POSTS

module.exports = {

    attributes: {
      title:        'string',
      content:      'string',
      coverImage:   'string',
      owner: {
          model: 'user'
      },
      tags: {
          collection: 'ContentTag',
                 via: 'posts',
            dominant: true // ---
      }
    }

};

      

MODEL TAGS

module.exports = {

  attributes: {
      name: 'string',
      posts: {
          collection: 'post',
          via: 'tags'
      }
  }
};

      

Now I want to get related posts with the same tags. I'm trying to play around with .populate ('tags') and .populate ('tags', {name: ['tag1', 'tag2']), but I can't figure out how to solve this.

+3


source to share


1 answer


You can cancel your request



Tags.find({name:['tag1','tag2']}).populate('posts')

+2


source







All Articles