gpt4 book ai didi

javascript - Sequelize : I want to return all registries associated with a model if one of these registries has a specific key

转载 作者:行者123 更新时间:2023-12-03 22:34:06 28 4
gpt4 key购买 nike

我有 标签 具有多对多关系,以及连接表 post_tags。如果帖子有一个特定的标签名称,我想从帖子中返回所有标签。
这个想法是按特定标签过滤所有帖子。
我是这样做的:

const posts = await Post.findAll({
include: {
model: Tag,
where: {
name: 'specificTag',
},
},
});
这样我可以过滤带有特定标签的帖子,但它不会返回与该帖子相关的所有其他标签。

最佳答案

尝试这样的事情:

const posts = await Post.findAll({
include: {
model: Tag,
where: {
name: ['specificTag'], // Same as using `name: { [Op.in]: ['specificTag'] }`
},
},
});
不过,我不确定。

关于javascript - Sequelize : I want to return all registries associated with a model if one of these registries has a specific key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63369409/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com