gpt4 book ai didi

javascript - 我如何包含模型数组?

转载 作者:行者123 更新时间:2023-12-02 21:23:38 25 4
gpt4 key购买 nike

var user = await db.user.findOne({
attributes: attributes,
include: ['charges',
'availability',
'practice',// 'services',
'education',// 'user_role',
'address',
'user_location',
// 'isAvailableStatus',
{ model: db.user_role, attributes: role_attributes },
{
model: db.user_service, as: 'services',
// ThIS IS MY QUESTION
include : [db.service_group, as : 'group']
//
},
],
where: {id: 0}
});

User -> user_role-> one of user_role # This is working
User -> user_service-> array of service_group # this is not working// my question

screen

如何包含模型数组?

最佳答案

您需要按如下方式修改您的代码。如果您正确定义了关联,那么您将获得预期的结果。

var user = await db.user.findOne({
attributes: {
include: [
'charges',
'availability',
'practice', // 'services',
'education', // 'user_role',
'address',
'user_location'
// 'isAvailableStatus',
]
},
include: [
{ model: db.user_role, attributes: role_attributes },
{
model: db.user_service,
as: 'services',
include: [{ model: db.service_group, as: 'group' }]
}
],
where: { id: 0 }
});

希望对你有帮助!

关于javascript - 我如何包含模型数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60793980/

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