Sails.js 查询水线关联

Sails.js query for waterline association

在 sails.js 中,我有一个 Post 模型与另一个名为 "tag"

的模型存在多对多关联

帖子模型

module.exports = {

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

};

标签模型

module.exports = {

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

现在我想获取具有相同标签的相关 Post。我试着玩弄 .populate('tags') 和 .populate('tags',{name: ['tag1','tag2']) 但我不能想办法解决。

您可以反向查询

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