- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 126
Closed
Description
Description and expected behavior
When using polymorphic relationships with @@delegate, queries fail with PrismaClientValidationError when trying to use where clauses on delegated fields in nested queries.
Queries with where clauses on delegated fields should and not throw any Prisma errors.
Reproduction
I've created a minimal reproduction: https://codesandbox.io/p/github/jagodin/zenstack-polymorphic-delegate-bug/main
Schema:
model Media {
  id Int @id @default(autoincrement())
  title String
  mediaType String
  
  @@delegate(mediaType)
  @@allow('all', true)
}
model Movie extends Media {
  director Director @relation(fields: [directorId], references: [id])
  directorId Int
  duration Int
  rating String
}
model Director {
  id Int @id @default(autoincrement())
  name String
  email String
  movies Movie[]
  
  @@allow('all', true)
}Working query:
await prisma.director.findMany({
  include: {
    movies: {
      orderBy: { title: 'asc' } // ✅ Works
    }
  }
})Failing query:
await prisma.director.findMany({
  include: {
    movies: {
      where: { title: 'Inception' } // ❌ Fails
    }
  }
})Environment (please complete the following information):
package.json:
{
    "name": "prisma-zenstack-polymorphic-relation-type-error",
    "version": "1.0.0",
    "main": "index.js",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "reproduce": "npx tsx src/index.ts",
        "setup": "npx zenstack generate && npx prisma migrate dev --name init"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "description": "",
    "devDependencies": {
        "@types/node": "^24.3.1",
        "prisma": "6.14.x",
        "tsx": "^4.20.5",
        "typescript": "^5.9.2",
        "zenstack": "2.18.1"
    },
    "dependencies": {
        "@prisma/client": "6.14.x",
        "@zenstackhq/runtime": "2.18.1"
    }
}Additional context
Add any other context about the problem here.
Metadata
Metadata
Assignees
Labels
No labels