【问题标题】:findFirst does not working with 3 filters on PrismafindFirst 不适用于 Prisma 上的 3 个过滤器
【发布时间】:2023-03-31 02:12:01
【问题描述】:

当我想检查我是否至少有一条带有参数的记录时,我遇到了这个问题。使用 2 个过滤器可以正常工作,但使用 3 个则无法正常工作。

await prismaClient.t_endereco
                .findFirst({
                    where: {
                        logradouro, (string)
                        bairro, (string)
                        numero, (number)
                    },
                })

更新记录的条件是没有另一个相同的。

我也尝试过使用 AND:

await prismaClient.t_endereco
                .findFirst({
                    where: {
                        AND:[
                              {logradouro}, 
                              {bairro}, 
                              {numero},  
                            ]
                        
                    },
                })

同样的问题。

有人帮我解决这个问题吗?

【问题讨论】:

    标签: javascript typescript orm prisma


    【解决方案1】:

    您可以尝试以下方法:

    const { PrismaClient } = require('@prisma/client')
    const prisma = new PrismaClient()
    
    prisma.category.findFirst({
      where: {
        OR: [
          { id: 2 },
          { name: 'new' },
          { description: 'd1' },
        ],
      },
    })
    .then(data => {
      console.log(data)
    })
    .catch(error => {
      console.error(error)
    })
    

    You can check the documentation for more information

    【讨论】:

      猜你喜欢
      • 2020-05-18
      • 2013-01-20
      • 1970-01-01
      • 1970-01-01
      • 2014-03-11
      • 2021-07-07
      • 2017-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多