0

大家好,我在我的节点 js 服务中使用 prisma 2,下面是我如何定义我的模型的架构

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())
}

所以我想将配置文件连接到对我的突变解析器的兴趣,但我不确定如何使用 prisma 2 连接多对多字段,这是我接近它的方式,但我被卡住了

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

      },

    })
4

0 回答 0