question: the Schema Types from the client don’t i...
# orm-help
f
question: the Schema Types from the client don’t include relational fields. Why is that? if i have an relation between things, and i include it, i get a lot of squiggles that are not true. Is there a setting to include them in the generate?
l
If it is like in Prisma 1, the relations is in an different promise-based type.
f
hm, i dont find any declaration for that in the generated prisma/index.d.ts
was it a different import?
l
Ok, maybe we're talking about different things. I meant the types (or interfaces) of what is returned from the prisma client, e.g. I have the type Process and in my index.ts I have interface Process and interface ProcessPromise, where the first has the non-relational fields only, and the second has every field, but behind promises. But a lot has changed since Prisma 1, so may not be relatable at all
f
Copy code
import { Comment as CommentSchema } from '@prisma/client';
comment doesnt have all fields, CommentPromise doesnt exist
lemme dive into the docs then, there has to be a way
r
@febreeze 👋 Could you share an example where you want the relation along with the base type? I can send you the correct way to get that as per your use case.
f
my solution rn:
Copy code
import {
    Comment as CommentSchema,
    User as UserSchema
} from '@prisma/client';


type ExtendedCommentSchema = CommentSchema & {
    user: UserSchema,
    children?: { [key: string]: ExtendedCommentSchema },
    _count: {
        children: number,
    }
}
the schema:
Copy code
model Comment {
  id        String @id @default(cuid())
  content   String
  upvotes   Int
  downvotes Int

  userId   String
  user     User?    @relation(fields: [userId], references: [id])
  votes    Vote[]
  map      Map?     @relation(fields: [mapId], references: [id])
  mapId    String?
  parentId String?
  Comment  Comment? @relation("CommentToComment", fields: [parentId], references: [id])

  createdAt DateTime @default(now())
  updatedAt DateTime @default(now())

  children Comment[] @relation("CommentToComment")

  @@map(name: "Comments")
}
r
This is easier and you don’t need to create your custom type and use Prisma’s types directly similar to Prisma’s API
Copy code
type T = Prisma.CommentGetPayload<{
    select: {
      _count: { select: { children: true } }
      user: true
      children: true
    }
  }>
f
cheers, i’ll try
👍 1
@Ryan this is what i ended up with, since i extend the schemas on runtime. works like a charm
👍 1