0

i am working on prisma orm and nest js. i want to store the array of object in the prisma. any body know how to dot it?? this is my prisma model

 model User {
  id         String     @id @default(uuid())
  firstName  String
  lastName   String
  email      String     @unique
  password   String
  isVerified Boolean
  isActive   Boolean
  createdAt  DateTime   @default(now())
  updatedAt  DateTime   @default(now())
  avatar     String?
  companyId  String
  schedule   Json[] 
  Company    Company    @relation(fields: [companyId], references: [id], onDelete: Cascade)
  Problem    Problem[]
  Payments   Payments[]
}

but it give this error enter image description here

any body know please rewrite this code

 const user = await this.prismaService.user.create({
    data: {
      email,
      firstName,
      lastName,
      password: hashedPassword,
      isActive: true,
      isVerified: false,
      companyId: company.id,
      schedule: [{
        key:"value1",
        key2:"value2"
      }],
    },

1 Answers1

0

I assume you are using Typescript.

const scheduleJson = [{
        key:"value1",
        key2:"value2"
      }] as Prisma.JsonArray

const user = await this.prismaService.user.create({
    data: {
      email,
      firstName,
      lastName,
      password: hashedPassword,
      isActive: true,
      isVerified: false,
      companyId: company.id,
      schedule: scheduleJson,
    }

Source: official docs https://www.prisma.io/docs/concepts/components/prisma-client/working-with-fields/working-with-json-fields#writing-to-a-json-field

thatVar
  • 152
  • 2
  • 7