2016-01-14 3 views
0

Как я могу найти коллекцию ассоциации и получить все результаты с этим запросом? Пример:Паруса/Ватерлиния: Найти по ассоциациям

ПОСТЫ МОДЕЛЬ

module.exports = { 

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

}; 

TAGS МОДЕЛЬ

module.exports = { 

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

мне нужно:

*POSTS.find({ 
    where: { 
    tags: 1 
    } 
}).populateAll() // All Post with ID tag 1* 

Без использования: TAGS.find ({id: 1})

ответ

0

Не уверен, что вы можете сделать это так, как хотите. Однако вы можете сделать следующее:

TAGS.find({id: 1}) 
.populate('posts') 
.then(function(tags) { 
    var posts = tags.posts 
    // 'posts' now has all posts associated with tags with id 1 
})