Heya friends. I was surprised to find that this `f...
# orm-help
k
Heya friends. I was surprised to find that this
findUnique
with an
include
resulted in two queries rather than one SQL query. Am I doing something wrong/misunderstanding something?
Copy code
const session = await prisma.session.findUnique({
  where: {id: sessionId},
  include: {user: true},
})
Results in:
Copy code
SELECT "public"."Session"."id", "public"."Session"."createdAt", "public"."Session"."userId", "public"."Session"."expirationDate" FROM "public"."Session" WHERE "public"."Session"."id" = $1 LIMIT $2 OFFSET $3

SELECT "public"."User"."id", "public"."User"."createdAt", "public"."User"."updatedAt", "public"."User"."email", "public"."User"."firstName", "public"."User"."discordId", "public"."User"."convertKitId", "public"."User"."role", "public"."User"."team" FROM "public"."User" WHERE "public"."User"."id" IN ($1) OFFSET $2
Is there a reason that can't be combined into a single query?
👀 1
r
Hey Kent 👋 Currently Prisma doesn’t use Joins but a multi query approach to fetch relations. We have a request for joins that you can check out 🙂 One reason I can think of why was it implemented in this way would be when you have separate resolvers in GraphQL and you would want to batch the query to prevent an N+1 problem. This is where separate queries seem to be useful over a single join.