最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Prisma 忽略了我传递给它的值

网站源码admin25浏览0评论

Prisma 忽略了我传递给它的值

Prisma 忽略了我传递给它的值

我正在使用 prisma 处理我的数据库。 这是我的约会表的架构:

model Appointment{
  id           String   @id @default(uuid())
  createdAt    DateTime @default(now())
  updatedAt    DateTime @updatedAt
  date         DateTime @db.DateTime()
  room         String   @db.VarChar(45)
  observations String   @db.VarChar(255)
  deleted      Boolean  @default(false)
  doctor       Medico   @relation(fields: [doctorId], references: [id])
  doctorId     String
  pacient       Utente   @relation(fields: [pacientId], references: [id])
  pacientId     String
}

这是我创建约会的方法(我使用 dayjs 将日期作为 YYYY-MM-DD 传递,而不是作为 prisma 的默认格式):

const add = (
  date: string,
  room: string,
  observations: string,
  pacientId: string,
  doctorId: string
) =>
  prisma.appointment.create({
    data: {
      date: dayjs(date, "YYYY-MM-DD").toDate(),
      room,
      observations,

      pacient: {
        connect: {
          id: pacientId,
        },
      },
      doctor: {
        connect: { id: doctorId },
      },
    },
    include: {
      pacient: { select: { name: true } },
      doctor: { select: { name: true, specialty: true } },
    },
  });

我正在使用 Insmomnia 来提出我的要求,这就是我要传递的:

{
"doctorId": "056d3771-07f3-4c5f-9c09-880989597787",
"pacientId": "221056c6-7075-4ae3-acdc-59c85935d6e5",
"date": "2024-05-02",
"room": "E42555",
"observations": "eat before arriving"
}

如您所见,我正在 2024-05-02 创建约会,但我得到的结果是:

{
"id": "250cd42c-2056-429b-908d-4c6e6a707e8f",
"createdAt": "2023-05-07T19:25:42.712Z",
"updatedAt": "2023-05-07T19:25:42.712Z",
"date": "2023-05-07T19:25:43.000Z",
"room": "E42555",
"observations": "eat before arriving",
"deleted": false,
"doctorId": "056d3771-07f3-4c5f-9c09-880989597787",
"pacientId": "221056c6-7075-4ae3-acdc-59c85935d6e5",
"pacient": {
    "name": "Adele"
},
"doctor": {
    "name": "Joe",
    "specialty": "general"
}
}

所以它返回当前日期和时间,而不是我之前通过的日期。 有什么想法吗?

回答如下:
发布评论

评论列表(0)

  1. 暂无评论