prisma / prisma1

💾 Database Tools incl. ORM, Migrations and Admin UI (Postgres, MySQL & MongoDB) [deprecated]
https://v1.prisma.io/docs/
Apache License 2.0
16.56k stars 867 forks source link

The type of `where` part of `delete` function is wrong when using `@@unique` #5180

Closed rostamiani closed 2 years ago

rostamiani commented 2 years ago

Describe the bug I have a model containing @@unique index. When I want to add where section to delete function it's type is wrong.

To Reproduce Generate this model:

model User {
  id        Int       @id @default(autoincrement())
  email     String    @unique
  password  String
  createdAt DateTime  @default(now())
  updatedAt DateTime  @updatedAt
  remarks   String?
  Channels  Channel[]
}

model Channel {
  id     Int    @id @default(autoincrement())
  name   String
  userId Int
  user   User   @relation(fields: [userId], references: [id])

  @@unique([userId, name])
  @@index([name])
}

It generates this class:

  export type ChannelDeleteArgs = {
    select?: ChannelSelect | null
    include?: ChannelInclude | null
    where: ChannelWhereUniqueInput
  }

  export type ChannelWhereUniqueInput = {
    id?: number
    userId_name?: ChannelUserIdNameCompoundUniqueInput
  }

The where part is different from find and create commands and does not have channel fields. Now I see this error:

'userId' does not exist in type 'ChannelWhereUniqueInput'

Expected behavior I want to delete a channel with this comand:

await this.prisma.channel.delete({ where: { id: 1, userId:1 } });

Versions (please complete the following information):