gpt4 book ai didi

javascript - Sequelize : How can I prevent virtual columns from included relation from appearing in query result?

转载 作者:行者123 更新时间:2023-12-03 22:38:50 25 4
gpt4 key购买 nike

我有一个看起来像这样的查询:

	return GroupMember.findOne({
where: { gid: gid, member_id: uid },
include: [
{
model: User,
as: 'member',
attributes: ['display_name'],
},
{
model: Group,
as: 'group',
attributes: ['name'],
}
]
});


因此,对于“成员”关系,我只请求“display_name”列。但是,用户模型在其中声明了 3 个虚拟列,即使我只要求“display_name”,它们也始终存在于查询结果中. 如何防止虚拟列出现在结果中?

最佳答案

所以为了排除虚拟列,你必须使用 exclude 属性的 attributes 字段,所以新的查询应该是这样的

    return GroupMember.findOne({
where: { gid: gid, member_id: uid },
include: [
{
model: User,
as: 'member',
attributes: { include: ['display_name'], exclude: ['virtual_columne_name1', 'virtual_columne_name2', 'virtual_columne_name3']},
},
{
model: Group,
as: 'group',
attributes: ['name'],
}
]
});

关于javascript - Sequelize : How can I prevent virtual columns from included relation from appearing in query result?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53754513/

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