findMany fetching only 1 entity from "includes"

for this query
const result = await prisma.member.findMany({
relationLoadStrategy: 'join',
where: {
userId,
},
include: {
organization: true,
},
});
const result = await prisma.member.findMany({
relationLoadStrategy: 'join',
where: {
userId,
},
include: {
organization: true,
},
});
I get this SQL generated
Query: SELECT "public"."member"."id", "public"."member"."organizationId", "public"."member"."userId", "public"."member"."role", "public"."member"."createdAt" FROM "public"."member" WHERE "public"."member"."userId" = $1 OFFSET $2
Params: ["jEH1abCLSHzG2Cn0RLPYZfFF23SUSSFW","0"]

Query: SELECT "public"."organization"."id", "public"."organization"."name", "public"."organization"."slug", "public"."organization"."logo", "public"."organization"."createdAt", "public"."organization"."metadata" FROM "public"."organization" WHERE "public"."organization"."id" IN ($1,$2) LIMIT $3 OFFSET $4
Params: ["iI4lYJix3QumBDM9hltFDtMDfs9sHHfS","vnweF8EA7u19xlkFq2w6JS13DWuyYUBe","1","0"]
Query: SELECT "public"."member"."id", "public"."member"."organizationId", "public"."member"."userId", "public"."member"."role", "public"."member"."createdAt" FROM "public"."member" WHERE "public"."member"."userId" = $1 OFFSET $2
Params: ["jEH1abCLSHzG2Cn0RLPYZfFF23SUSSFW","0"]

Query: SELECT "public"."organization"."id", "public"."organization"."name", "public"."organization"."slug", "public"."organization"."logo", "public"."organization"."createdAt", "public"."organization"."metadata" FROM "public"."organization" WHERE "public"."organization"."id" IN ($1,$2) LIMIT $3 OFFSET $4
Params: ["iI4lYJix3QumBDM9hltFDtMDfs9sHHfS","vnweF8EA7u19xlkFq2w6JS13DWuyYUBe","1","0"]
The issue is that second select has LIMIT 1, so if there are multiple member rows, only first one will get organization relation set. Why is that? The other issue is it obviously did not use joins. This is my Prisma settings:
generator client {
provider = "prisma-client"
output = "../prisma-generated"
previewFeatures = ["queryCompiler", "driverAdapters", "relationJoins", "typedSql"]
}

datasource db {
provider = "postgresql"
url = env("DB_CONNECTION_STRING")
}
generator client {
provider = "prisma-client"
output = "../prisma-generated"
previewFeatures = ["queryCompiler", "driverAdapters", "relationJoins", "typedSql"]
}

datasource db {
provider = "postgresql"
url = env("DB_CONNECTION_STRING")
}
3 Replies
Prisma AI Help
Prisma AI Help7mo ago
You selected to wait for the human sages. They'll share their wisdom soon. Grab some tea while you wait, or check out #ask-ai if you'd like a quick chat with the bot anyway!
Saša Šijak
Saša ŠijakOP7mo ago
this is driving me bonkers
Nurul
Nurul7mo ago
Hey! This issue will be fixed in release happening on next Tuesday https://github.com/prisma/prisma/issues/27137 Sorry about the inconvenience 🙏
GitHub
Fetching with include on one-to-one related field only gets first...
Bug description Using Prisma v6.7.0 with previewFeatures = ["queryCompiler", "driverAdapters"], one-to-one relationships aren't properly fetched when used in an include. Exa...

Did you find this page helpful?