Here we have a relation between ticket and refund.
This will generated something like:
SELECT
"public"."ticket"."id"
FROM
"public"."ticket"
WHERE ("public"."ticket"."type" = 'SELL'
AND "public"."ticket"."status" = 'REFUNDED'
AND("public"."ticket"."id")
IN(
SELECT
"t0"."id" FROM "public"."ticket" AS "t0"
INNER JOIN "public"."ticket_refund" AS "j0" ON ("j0"."ticket_id") = ("t0"."id")
WHERE ("j0"."created_at" >= '2022-04-01'::TIMESTAMP
AND "t0"."id" IS NOT NULL))
AND("public"."ticket"."id")
IN(
SELECT
"t0"."id" FROM "public"."ticket" AS "t0"
INNER JOIN "public"."ticket_refund" AS "j0" ON ("j0"."ticket_id") = ("t0"."id")
WHERE ("j0"."created_at" <= '2022-09-01'::TIMESTAMP
AND "t0"."id" IS NOT NULL)))
Suggested solution
Prisma should be able to rewrite conditions to avoid unnecessary joins.
Problem
It is easy for users to mess up and created really bad queries when using filters on related fields.
Consider:
Here we have a relation between
ticket
andrefund
. This will generated something like:Suggested solution
Prisma should be able to rewrite conditions to avoid unnecessary joins.
Alternatives
Do: