我要在不同的表中找到一个字段,即我要检查搜索是否在Customer表的不同字段、Shops表的不同字段和ContactPerson表的不同字段中Customer 和 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:无法绑定多部分标识符“ContactPersons.contactp_mobile”。(以及所有相关字段的此错误。)我能为那工作做些什么?
1 回答

呼唤远方
TA贡献1856条经验 获得超11个赞
解决了!
经过大量测试后,我发现错误无关,也不在 OR 中,在 LIMIT 中。
搜索后我解决了这个添加duplicating: false包括。
最后的代码是这样的:
var result = await CustomerModel.findAll({
include: [
{model : ShopModel, require: true, duplicating: false},
{model: ContactPersonModel, require: true, duplicating: false}
],
...params,
raw
})
添加回答
举报
0/150
提交
取消