Sails.js 帆/水线:通过协会查找
如何通过集合关联查找并获取该查询的所有结果? 例如: POSTS模型Sails.js 帆/水线:通过协会查找,sails.js,Sails.js,如何通过集合关联查找并获取该查询的所有结果? 例如: POSTS模型 module.exports = { attributes: { title: 'string', content: 'string', coverImage: 'string', owner: { model: 'user' }, tags: { collection: 'Co
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'
}
}
};
我需要:
*POSTS.find( {
where: {
tags: 1
}
}).populateAll() // All Post with ID tag 1*
不使用:
TAGS.find({id:1})不确定是否可以按您想要的方式执行。但是,您可以做的是:
TAGS.find({id: 1})
.populate('posts')
.then(function(tags) {
var posts = tags.posts
// 'posts' now has all posts associated with tags with id 1
})
不确定你是否能按你想要的方式做。但是,您可以做的是:
TAGS.find({id: 1})
.populate('posts')
.then(function(tags) {
var posts = tags.posts
// 'posts' now has all posts associated with tags with id 1
})