Prisma 忽略了我传递给它的值

编程入门 行业动态 更新时间:2024-10-03 17:12:31

Prisma <a href=https://www.elefans.com/category/jswz/34/1754742.html style=忽略了我传递给它的值"/>

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"
}
}

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

回答如下:

更多推荐

Prisma 忽略了我传递给它的值

本文发布于:2024-05-30 21:51:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770963.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:忽略了   Prisma

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!