当前遇到个问题,gorm 中多个字段任意组合查询,需要构造成底层转化为sql 为select id from table where (num,name) in ((num1,'name1'),(num2,'name2')),
问题是gorm
尝试解决1:查询的结果db.Where("tenant_id in (?) or region_id in (?) or status in (?)",",tenantIdList,regionIdList,statusList),
转化为sql为 SELECT count(*) FROM `orders` WHERE ( tenant_id in ('tenant_1','tenant_2','admin') or region_id in ('1,2,4') or status in ('1,4')),查询不到结果
尝试解决2:db.Where("order_name like ? and (tenant_id,region_id,status) in (?,?,?)",
// "%"+query+"%",tenantIdList,regionIdList,statusList). 直接报转化为sql报错
有疑问加站长微信联系(非本文作者)