When does _count exist in prisma?

What's the difference between post and category that the category has a _count field available? here's the relevant parts in the schema
model Category{
id Int @id @default(autoincrement())
uuid String @unique @default(uuid())
name String @unique
description String
link String @unique

posts Post[]
parentCategoryUUID String?
parentCategory Category? @relation("CategoryStructure", fields: [parentCategoryUUID], references: [uuid])
childCategories Category[] @relation("CategoryStructure")
}

model Post {
id Int @id @default(autoincrement())
uuid String @unique @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

title String
content String
published Boolean @default(false)

excerpt String
mainImage String
keywords String @default("[]") // This is JSON. SQLite doesn't support String[] yet

category Category @relation(fields: [categoryUUID], references: [uuid])
categoryUUID String

author User @relation(fields: [authorUUID], references: [uuid])
authorUUID String
}
model Category{
id Int @id @default(autoincrement())
uuid String @unique @default(uuid())
name String @unique
description String
link String @unique

posts Post[]
parentCategoryUUID String?
parentCategory Category? @relation("CategoryStructure", fields: [parentCategoryUUID], references: [uuid])
childCategories Category[] @relation("CategoryStructure")
}

model Post {
id Int @id @default(autoincrement())
uuid String @unique @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

title String
content String
published Boolean @default(false)

excerpt String
mainImage String
keywords String @default("[]") // This is JSON. SQLite doesn't support String[] yet

category Category @relation(fields: [categoryUUID], references: [uuid])
categoryUUID String

author User @relation(fields: [authorUUID], references: [uuid])
authorUUID String
}
3 Replies
cje
cje2y ago
category has a one to many with post what you're actually doing here is _count: { post: true }
scinorandex
scinorandex2y ago
Thank you.
Want results from more Discord servers?
Add your server