gpt4 book ai didi

javascript - 使用 OR 序列化多表关联查询

转载 作者:行者123 更新时间:2023-11-29 22:50:21 25 4
gpt4 key购买 nike

我要在不同的表中查找一个字段,即我要检查是否在Customer表的不同字段中,在Shops表的不同字段中,在ContactPerson表的不同字段中查找

Customer and Persons 和 Customer Shops 表是 1-N 并且是关联的

我的“搜索”变量是我想要找到的。

这是我的代码

CustomerPersonsRelation()
CustomerShop()
var result = await CustomerModel.findAll({
...params,
include: [
{model : ShopModel},
{model: ContactPersonModel}
]
})

一切都是进口的,不用担心。我的参数是这些:

{
where: {
$or: [
{
'$Customer.customer_name$': { $like: '%' + search + '%' },
},
{
'$Customer.customer_fiscal_name$': { $like: '%' + search + '%' },
},
{
'$Customer.customer_responsable_name$': { $like: '%' + search + '%' },
},
{
'$Customer.customer_responsable_phone$': { $like: '%' + search + '%' },
},
{
'$Customer.customer_web$': { $like: '%' + search + '%' },
},
{
'$Shops.shop_name$': { $like: '%' + search + '%' },
},
{
'$Shops.shop_phone$': { $like: '%' + search + '%' },
},
{
'$Shops.shop_mobile$': { $like: '%' + search + '%' },
},
{
'$ContactPersons.contactp_name$': { $like: '%' + search + '%' },
},
{
'$ContactPersons.contactp_phone$': { $like: '%' + search + '%' },
},
{
'$ContactPersons.contactp_mobile$': { $like: '%' + search + '%' },
}
]
},
limit: 3
})
}

但是返回这个错误:错误:SequelizeDatabaseError:无法绑定(bind)多部分标识符“ContactPersons.contactp_mobile”。 (以及所有相关字段的此错误。)

我能为它做些什么?

最佳答案

解决了!

经过大量测试后,我发现错误不相关,不在 OR 中,而是在 LIMIT 中。

搜索后我解决了这个添加 duplicating: false in includes 的问题。

最终代码是这样的:

    var result = await CustomerModel.findAll({
include: [
{model : ShopModel, require: true, duplicating: false},
{model: ContactPersonModel, require: true, duplicating: false}
],
...params,
raw
})

关于javascript - 使用 OR 序列化多表关联查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57571795/

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