Reputation: 206
In sails.js I've a Post model with a many-to-many association with another model called "tag"
POSTS MODEL
module.exports = {
attributes: {
title: 'string',
content: 'string',
coverImage: 'string',
owner: {
model: 'user'
},
tags: {
collection: 'ContentTag',
via: 'posts',
dominant: true // ---
}
}
};
TAGS MODEL
module.exports = {
attributes: {
name: 'string',
posts: {
collection: 'post',
via: 'tags'
}
}
};
Now I want to get the related Posts with the same tags. I've try to play around with .populate('tags') and and .populate('tags',{name: ['tag1','tag2']) but I can't figure out how to solve.
Upvotes: 3
Views: 1176
Reputation: 5979
You can reverse your query
Tags.find({name:['tag1','tag2']}).populate('posts')
Upvotes: 3