我想使用Pony动态构建查询,但我想将过滤器与OR
而不是 with结合起来AND
。也就是说,我想做这样的事情:
keywords = ['gizmo', 'gadget']
query = select(w for w in Widget)
for kw in keywords:
query = query.filter(lambda w: kw in w.name)
for item in query:
print(item)
当然,上面的问题是它会产生如下查询:
SELECT "w"."id", "w"."name"
FROM "Widget" "w"
WHERE "w"."name" LIKE '%gizmo%'
AND "w"."name" LIKE '%gadget%'
而我想要:
SELECT "w"."id", "w"."name"
FROM "Widget" "w"
WHERE "w"."name" LIKE '%gizmo%'
OR "w"."name" LIKE '%gadget%'
有没有办法到达那里?