Home > Back-end >  How can I create a nested item in the DB?
How can I create a nested item in the DB?

Time:08-13

I am having several problems when I try to create a new user with a nested related table. My schema is like this:

model User {
    id                Int                 @id @default(autoincrement())
    username          String              @unique
    email             String              @unique
    avatar            String              @default("none")
    role              Role                @default(USER)
    password          String
    maxScore          Int                 @default(0)
    UserCategoryStats UserCategoryStats[]
}

model UserCategoryStats {
    id               Int      @id @default(autoincrement())
    user             User     @relation(fields: [userId], references: [id])
    userId           Int
    category         Category @relation(fields: [categoryId], references: [id])
    categoryId       Int
    correctAnswers   Int      @default(0)
    incorrectAnswers Int      @default(0)
    totalAnswers     Int      @default(0)
    timesChosen      Int      @default(0)
}

And I am just trying to create an user with one(or more) UserCategoryStats enter image description here

  • Related