繁体   English   中英

Prisma findMany失败

[英]Prisma findMany failing

最近我将 prisma 从 2.7.0 更新到 2.19.0,我分别进行了更改(主要是 findOne 到 findUnique)但是这个拒绝工作:

const eventFilter = { AND: [
    { startTime: { lte: moment().toISOString() } },
    { endTime: { gte: moment().toISOString() } },
    { place:{ id: placeId || { not: null } } }
 ] }

await prisma.eventParticipant.findMany({
    where: {
        user: { id: XXX },
        event: eventFilter
    }
})

但这样做会引发此错误(短版呵呵): Unknown arg `AND` in where.event.AND for type EventRelationFilter

所以我在index.d.ts (在 node_modules/.prisma/client) findMany(...)参数的类型,我发现:

findMany<T extends EventParticipantFindManyArgs>(
      args?: SelectSubset<T, EventParticipantFindManyArgs>
    ): CheckSelect<T, PrismaPromise<Array<EventParticipant>>, PrismaPromise<Array<EventParticipantGetPayload<T>>>>

然后我寻找EventParticipantFindManyArgs有什么:

export type EventParticipantFindManyArgs {
    // Has another props but this one is that interest
    where?: EventParticipantWhereInput
}

再一次...寻找EventParticipantWhereInput有什么:

export type EventParticipatnWhereInput {
    // Like before, this one has another props but this one is that interest
    event?: XOR<EventRelationFilter, EventWhereInput> | null
}

在这一点上,我希望eventFilter (我的 const)适合EventParticipatnWhereInput.event类型

最后我寻找EventRelationFilter它有:

export type EventRelationFilter = {
    is?: EventWhereInput | null
    isNot?: EventWhereInput | null
}

Aaand EventWhereInput拥有eventFilter拥有的所有道具

所以......当我看到它时,我说:“为什么我的eventFilter object 不适合作为EventWhereInput ?”

我试图解决这个问题:

import { Prisma } from '@prisma/client' // Import types from exported namespace called "Prisma"

// This one doesn't throw error like "{...} is not assignable to object of type Prisma.EventWhereInput
// So I assume this is fine
const eventFilter: Prisma.EventWhereInput = { AND: [
    { startTime: { lte: moment().toISOString() } },
    { endTime: { gte: moment().toISOString() } },
    { place:{ id: placeId || { not: null } } }
 ] }

但是,这样做没有任何改变。 和以前一样的错误(prisma 期望 where.event 是“EventRelationFilter”类型)

所以我说“好吧,你的棱镜,我会让eventFilter “EventRelationFilter”类型:

import { Prisma } from '@prisma/client' // Import types from exported namespace called "Prisma"

// This one doesn't throw error like "{...} is not assignable to object of type Prisma.EventRelationFilter
// So I assume this is fine too
const eventFilter: Prisma.EventRelationFilter = { is: { AND: [
    { startTime: { lte: moment().toISOString() } },
    { endTime: { gte: moment().toISOString() } },
    { place:{ id: placeId || { not: null } } }
 ] } }

但是(从这一点开始,我的希望已经转移到 stackoverflow 上)抛出这个错误: Unknown arg `is` in where.event.is for type EventWhereInput

我说:“什么??都是错误?棱镜想从我这里得到什么?”

抱歉,我的问题很长,但我对此很困惑。

顺便说一句: eventParticipants 是用户和事件之间的“连接表”,我不确定

编辑:架构:

model Event {
  id               Int                @id @default(autoincrement())
  name             String
  description      String?
  // ... 
  participantUsers EventParticipant[]
}


model User {
  id                        Int                    @id @default(autoincrement())
  name                      String
  alias                     String?                @unique @default(dbgenerated())
  birthDay                  DateTime?              @map("dateOfBirth")
  // ...                    
  event                     Event[]
  @@map(name: "user")
}

model EventParticipant {
  id       Int      @id @default(autoincrement())
  event_id Int?
  user_id  Int?
  event    Event?   @relation(fields: [event_id], references: [id])
  user     User?    @relation("event_participants_idToUser", fields: [user_id], references: [id])
  @@map(name: "event_participants")
}

谢谢!

抱歉,我的错误... place: { id: { not: null } } "not" 期望有一个NestedIntFilternumber ,所以null是该键的无效值

const eventFilter: Prisma.EventWhereInput = { AND: [
    { startTime: { lte: moment().toISOString() } },
    { endTime: { gte: moment().toISOString() } },
    // WRONG { place:{ id: placeId || { not: null } } }
    { place:{ id: placeId } } // FINE!
 ] }

需要以另一种方式修复该验证.. 奇怪的是,我的 IDE 没有抛出像{...} is not assignable to Prisma.EventWhereInput或类似的东西。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM