model Client {
  id          Int            @id @default(autoincrement())
  createdAt   DateTime       @default(now())
  email       String         @unique
  name        String?
  lastName    String?
  password    String?
  profile     ClientProfile?
  franchise   Franchise      @relation(fields: [franchiseId], references: [id])
  franchiseId Int
  Records     Record[]
}

model ClientProfile {
  id                      Int       @id @default(autoincrement())
  createdAt               DateTime  @default(now())
  photo                   String?
  age                     DateTime?
  sex                     String?
  birthDate               DateTime?
  phone                   String?
  alternativePhone        String?
  documentType            String?
  documentNumber          String?
  taxIdentificationNumber String?
  frontPhotoID            String?
  IdPhotoBack             String?
  nationality             String?
  province                String?
  city                    String?
  note                    String?
  country                 String?
  address                 String?
  clientId                Int?      @unique
  client                  Client?   @relation(fields: [clientId], references: [id])
}

我的目标是检索具有特定特许经营权ID和特定文档编号的用户.我正在try 使用Prisma客户端查询来实现这一点:

const client = await this.prisma.userClient.findUnique({
  where: {
    franchiseId: 1,
    clientProfile: {
      documentNumber: "23212123221"
    }
  }
});

我正在将NodeJS与Prisma客户端一起使用

推荐答案

您的查询将如下所示:

  const client = await prisma.client.findFirst({
    where: {
      franchiseId: 1,
      profile: {
        documentNumber: "123",
      },
    },
  });

如果要使用findUnique,则需要在WHERE子句中传递至少一个唯一属性.

Javascript相关问答推荐

如何在加载的元数据上使用juserc和await中获得同步负载?

我不知道为什么我的JavaScript没有验证我的表单

将json数组项转换为js中的扁平

引用在HTMLAttributes<;HTMLDivElement>;中不可用

阿波罗返回的数据错误,但在网络判断器中是正确的

如何在使用rhandsontable生成表时扩展数字输入验证?

如何发送从REST Api收到的PNG数据响应

元素字符串长度html

如何用javascript更改元素的宽度和高度?

输入的值的类型脚本array.排序()

如何根据输入数量正确显示alert ?

如何根据查询结果重新排列日期

如何修复错误&语法错误:不能在纯react 项目中JEST引发的模块&之外使用导入语句?

Reaction即使在重新呈现后也会在方法内部保留局部值

P5JS-绘制不重叠的圆

每隔3个项目交替显示,然后每1个项目交替显示

我在哪里添加过滤器值到这个函数?

如何阻止外部脚本进入顶层导航

如何使用fltter_js将对象作为参数传递给javascrip?

验证Java脚本函数中的两个变量