-
Notifications
You must be signed in to change notification settings - Fork 26
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
Implement DtoRelationCanDisconnectOnUpdate annotation #25
Conversation
@Brakebein it would be super cool if you could check and merge this, thanks for you work! |
Thanks! I will be able to look at it next week. |
After reading the docs (https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#disconnect) and playing around with the Prisma client, I found some caveats: According to the docs, the disconnect update field is only available for optional relation fields. Hence, for the sample schema, it should not be possible to create a disconnect field for company, which is declared as a mandatory field. Though, it would be possible, for example, for the optional photo field. prisma.product.update({
where: { id: '123' },
data: {
photo: {
disconnect: true,
},
company: {
// disconnect not available
},
},
}); The question is, if it should be skipped automatically in this case (maybe with a warning), or if the user should be responsible to not add this annotation to the company field? However, it seems to be possible to do it the other way round. I don't know what happens to the mandatory field then. But this should not be our problem in the scope of this generator. I was just wondering. prisma.company.update({
where: { id: '456' },
data: {
product: {
disconnect: { id: '123' },
},
},
}); Adding the annotation to a relation list field produces the correct disconnect field 👍 model Photo {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
/// @DtoRelationCanDisconnectOnUpdate
product Product[]
} |
Good point, I think this is a thing the library should address! I've added a check which throws an error if a relation is required and is not a list. |
Regarding the required 1:n where you disconnect from the n side: I would agree that this is beyond the scope of the generator. |
Thanks for merging!
The |
I think I found the cause, I'll open a PR |
Add a "@DtoRelationCanDisconnectOnUpdate" annotation which enables to auto generate disconnect fields on the connect DTO