Create Prisma 2 Mutation on many to many field using Nexus

1.2k views Asked by At

Hello guys i'm using prisma 2 in my node js serve and below is how i defined the schema of my models

model Interest {
  id        Int       @default(autoincrement()) @id
  name      String
  profile   Profile[] @relation(references: [id])
  createdAt DateTime  @default(now())
  updatedAt DateTime  @default(now())
}
model Profile {
  id         Int        @default(autoincrement()) @id
  username   String     @unique
  user       User       @relation(fields: [userId], references: [id])
  interests  Interest[] @relation(references: [id])
  userId     Int
  dob        String
  location   String
  skills     String
  profession String
  createdAt  DateTime   @default(now())
  updatedAt  DateTime   @default(now())
}

So i want to connect profile to interest in my mutation resolver, but i'm not sure how to connect many to many field using prisma 2 this how i approached it, but i'm stuck

return ctx.prisma.profile.create({
      data: {
        dob: dob,
        location: location,
        profession: profession,
        skills: skills,
        username: username,
        user: {
          connect: {
            id: Number(userId),
          },
        },
        interests: {
          create: []
        }

      },

    })
0

There are 0 answers