Closed bring-shrubbery closed 1 year ago
@bring-shrubbery @kristinlindquist Please check these two PRS and let me know if it works fine for you. (tRPC Generator): #45 (Zod Generator): https://github.com/omar-dulaimi/prisma-zod-generator/pull/42
CC: @Shahidul1004 @BitPhoenix
Hiding models will look like this in your Prisma schema:
/// @@Gen.model(hide: true)
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}
@omar-dulaimi Seems to work for me. Maybe it would also be useful to add a relation to the hidden "Map" model in the example schema? This would test the hiding of the parameter when it's referenced from somewhere? Maybe something like this:
model Post {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String
content String?
published Boolean @default(false)
viewCount Int @default(0)
author User? @relation(fields: [authorId], references: [id])
authorId Int?
likes BigInt
maps Map[]
}
/// @@tRPCGen.model(hide: true)
model Map {
key String @id
value String
Post Post? @relation(fields: [postId], references: [id])
postId Int?
}
Problem
Some of the models created in Prisma schema are not meant to be touched by the frontend at all. As an example,
VerificationToken
from the NextAuth is not something I want to be able to interact with from the client-side - I want to leave it to NextAuth to deal with it.Suggested solution
It would be great to be able to disable the generation of a router for the Prisma model by using a simple comment, something like following:
I understand that it's not as straightforward as just ignoring the model, since other models might reference the ignored one. In this case, the other model's router should also not include the ignored model, so the property that references it should be removed.
Alternatives
If this feature already exists, would be nice to have it documented in README