【发布时间】:2019-02-22 07:23:29
【问题描述】:
我要查找的是首先选择那些包含我的搜索参数的 cmets,它将返回 postId,然后选择包含所有 cmets 的整个帖子,包括我们使用搜索参数搜索过的评论!
app.get('/search_', (req, res, next) => {
var search = req.query.search;
comment.findAll({
attributes: ['PostId'],
where: {
the_comments: {
[Op.like]: `%${search}%`
}
}
})
.then(data => {
var array = [ ];
for (var x in data) {
console.log(data[x].PostId);
array.push(data[x].PostId);
}
console.log(array);
Post.findAll({
include: [
{
model: comment
}
],
where: {
id: {
[Op. in]: [array]
}
}
})
.then(result => {
res.json(result);
})
})
});
【问题讨论】:
标签: mysql sql node.js sequelize.js