-
-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve explicit many-to-many #59
Comments
What do you mean by 'have to provide extra information'? I'm genuinely confused 😅 |
ExampleSchemamodel Program {
id Int @id @default(autoincrement())
grantor GrantorOnPrograms[]
}
model Grantor {
name String @id
programs GrantorOnPrograms[]
}
model GrantorOnPrograms {
id Int @id @default(autoincrement())
program Program @relation(fields: [programId], references: [id])
programId Int
grantor Grantor @relation(fields: [grantorName], references: [name])
grantorName String
} InsertYou can't just do: db.program()
.create(
program::id::set(123),
vec![program::grantor::link(vec![
grantor::name::equals("whatever"),
])],
)
.exec()
.await?; You have to use the join table: db.program()
.create(
program::origin::set(construct_program_link(url)),
vec![program::grantor::link(vec![
grantor_on_programs::id::equals(12345),
])],
)
.exec()
.await?; It would be nice if the client automatically resolves the join table References |
The problem with doing so is that the client isn't aware of what a join table is and I don't plan for it to ever be. That is not a feature Prisma Client JS has, and it kind of defeats the purpose of an explicit join table in the first place, since they are supposed to yield control of the join table from Prisma to you. If you want nested creates, which would allow the Program and GrantorOnPrograms records to be created in the same query, I have planned it in #44 but probably won't implement it for a while. Also, if you have a join table like the example you provided, it's probably worth just using an implicit one. Not sure of your exact use case though. |
Ah, okay. Understandable. I thought that the js client would allow the join tables to be automated. |
It would be nice if you could use explicit m2m relations the same way as implicit ones.
Currently you have to provide extra information for explicit relations, but I think you could probably infer that stuff from the prisma schema?
The text was updated successfully, but these errors were encountered: