3 way join with @@id failing when querying
I am using prisma2 preview and i have the following 3-way join defined in my schema:
model UserOrganization {
organization Organization
role Role
user User
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@id(fields: [role, user, organization])
}
when i run
await this.prismaService.prisma.userOrganization.findMany({
where: { user: { id: 11 } },
});
I get the following error
2020-02-18T21:47:16.683Z prisma-client [
'query {\n' +
' findManyUserOrganization(where: {\n' +
' user: {\n' +
' id: 11\n' +
' }\n' +
' }) {\n' +
' createdAt\n' +
' updatedAt\n' +
' }\n' +
'}'
]
2020-02-18T21:47:16.687Z engine stdout {
timestamp: 'Feb 18 13:47:16.687',
level: 'ERROR',
target: 'prisma',
fields: {
message: 'PANIC',
reason: 'Expected ID field role to be present on the model',
file: 'src/libcore/option.rs',
line: 1188,
column: 5
}
}
2020-02-18T21:47:16.688Z engine:log {
timestamp: 2020-02-18T21:47:16.687Z,
level: 'error',
target: 'prisma',
fields: {
message: 'PANIC',
reason: 'Expected ID field role to be present on the model',
file: 'src/libcore/option.rs',
line: 1188,
column: 5
}
}
2020-02-18T21:47:16.692Z engine {
error: Error: socket hang up
at connResetException (internal/errors.js:604:14)
at Socket.socketOnEnd (_http_client.js:460:23)
at Socket.emit (events.js:333:22)
at endReadableNT (_stream_readable.js:1204:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'ECONNRESET'
}
}
2020-02-18T21:47:16.695Z prisma-client Error: PANIC
at /usr/src/app/node_modules/@prisma/client/runtime/index.js:1:15642
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at Dataloader.loader (/usr/src/app/node_modules/@prisma/client/index.js:55:23)
[Nest] 29 - 02/18/2020, 1:47:16 PM [ExceptionsHandler]
Invalid `prisma.userOrganizations.findMany()` invocation in
/usr/src/app/src/organizations/organizations.service.ts:60:70
PANIC +8157ms
Error:
Invalid `prisma.userOrganizations.findMany()` invocation in
/usr/src/app/src/organizations/organizations.service.ts:60:70
PANIC
at PrismaClientFetcher.request (/usr/src/app/node_modules/@prisma/client/index.js:89:17)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
The full schema is:
// Set connection url from enviroment
datasource mysql {
provider = "mysql"
url = env("MYSQL_URL")
enabled = true
}
generator client {
provider = "prisma-client-js"
binaryTargets = ["native"]
}
model Organization {
id Int @default(autoincrement()) @id
uid String? @unique
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
}
model UserOrganization {
organization Organization
role Role
user User
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@id(fields: [role, user, organization])
}
model User {
id Int @default(autoincrement()) @id
uid String? @unique
email String @unique
firstName String?
lastName String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
}
model Role {
id Int @default(autoincrement()) @id
uid String? @unique
name String
description String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
Can you build a reproduction for this please @pantharshit00? Thanks.
I can reproduce. Not sure we have filtering field with @@id implemented yet.
Here is a minimal reproducetion though: https://github.com/harshit-test-org/prisma2-client-502
This is probably related to this: https://github.com/prisma/prisma2/issues/1681 So yes, this is indeed to what we internally call "AUMFIDARR" which has to do with limited functionality related to @@id. This will hopefully be fixed soon.
Using @pantharshit00 's reproduction from above, after updating to 2.0.0-preview024, I can not reproduce this error any more:
C:\Users\Jan\Documents\throwaway\prisma2-client-502>node index.js
[]
^C
C:\Users\Jan\Documents\throwaway\prisma2-client-502>set DEBUG=*
C:\Users\Jan\Documents\throwaway\prisma2-client-502>node index.js
prisma-client {
prisma-client engineConfig: {
prisma-client cwd: 'C:\\Users\\Jan\\Documents\\throwaway\\prisma2-client-502\\prisma',
prisma-client debug: false,
prisma-client datamodelPath: 'C:\\Users\\Jan\\Documents\\throwaway\\prisma2-client-502\\node_modules\\@prisma\\client\\schema.prisma',
prisma-client prismaPath: undefined,
prisma-client datasources: [],
prisma-client generator: {
prisma-client name: 'client',
prisma-client provider: 'prisma-client-js',
prisma-client output: 'C:\\Users\\Jan\\Documents\\throwaway\\prisma2-client-502\\node_modules\\@prisma\\client',
prisma-client binaryTargets: [],
prisma-client config: {}
prisma-client },
prisma-client showColors: true,
prisma-client logLevel: undefined,
prisma-client logQueries: undefined,
prisma-client env: { MYSQL_URL: 'mysql://root:root@localhost:3306/_issue_client_502' },
prisma-client flags: []
prisma-client }
prisma-client } +0ms
prisma-client Prisma Client call: +51ms
prisma-client prisma.userorganization.findMany({
prisma-client where: {
prisma-client user: {
prisma-client id: 11
prisma-client }
prisma-client }
prisma-client }) +16ms
prisma-client Generated request: +4ms
prisma-client query {
prisma-client findManyuserorganization(where: {
prisma-client user: {
prisma-client id: 11
prisma-client }
prisma-client }) {
prisma-client createdAt
prisma-client updatedAt
prisma-client }
prisma-client }
prisma-client +2ms
getos { platform: 'win32', libssl: undefined } +0ms
engine {
engine PRISMA_DML_PATH: 'C:\\Users\\Jan\\Documents\\throwaway\\prisma2-client-502\\node_modules\\@prisma\\client\\schema.prisma',
engine PORT: '59828',
engine RUST_BACKTRACE: '1',
engine RUST_LOG: 'info',
engine OVERWRITE_DATASOURCES: '[]',
engine CLICOLOR_FORCE: '1'
engine } +0ms
engine {
engine cwd: 'C:\\Users\\Jan\\Documents\\throwaway\\prisma2-client-502\\prisma'
engine } +4ms
engine { flags: [ '--enable-raw-queries' ] } +3ms
engine stderr Printing to stderr for debugging +36ms
engine stdout {
timestamp: 'Mar 19 01:11:04.506',
level: 'INFO',
target: 'quaint::pooled',
fields: { message: 'Starting a mysql pool with 9 connections.' }
} +12ms
engine stderr Listening on 127.0.0.1:59828 +7ms
engine stdout {
timestamp: 'Mar 19 01:11:04.522',
level: 'INFO',
target: 'prisma::server',
fields: {
message: 'Started http server on 127.0.0.1:59828',
'log.target': 'prisma::server',
'log.module_path': 'prisma::server',
'log.file': 'query-engine/prisma/src/server.rs',
'log.line': 95
}
} +2ms
[]
^C
Yay! 🚀
@toriaezunama Can you please confirm that it also works for you now? Thanks.
It works thanks.