I have the following model (which was suggested by...
# orm-help
r
I have the following model (which was suggested by next-auth):
Copy code
model Account {
  id                 Int       @default(autoincrement()) @id
  compoundId         String    @unique @map(name: "compound_id")
  userId             Int       @map(name: "user_id")
  providerType       String    @map(name: "provider_type")
  providerId         String    @map(name: "provider_id")
  providerAccountId  String    @map(name: "provider_account_id")
  refreshToken       String?   @map(name: "refresh_token")
  accessToken        String?   @map(name: "access_token")
  accessTokenExpires DateTime? @map(name: "access_token_expires")
  createdAt          DateTime  @default(now()) @map(name: "created_at")
  updatedAt          DateTime  @default(now()) @map(name: "updated_at")

  @@index([providerAccountId], name: "providerAccountId")
  @@index([providerId], name: "providerId")
  @@index([userId], name: "userId")

  @@map(name: "accounts")
}
How do I delete an entry by specifing a userId now? I tried this
Copy code
await prisma.account.delete({
    where: {
      userId: userId,
    },
  });
which results in
Type '{ userId: number; }' is not assignable to type 'AccountWhereUniqueInput'.
l
The userId field needs to be tagged as unique
r
Yeah either that or you would need to use
deleteMany
instead.
d
userId is of type number, and I guess userId is coming from req.params, which gives you a string so, { userId: Number(userId) } should work.
r
it works with deleteMany, thanks
so because its not marked as unique in the schema
interesting
maybe because the same user can have different ways of logging in, then there are two account entries
l
The delete (to delete one) requires a unique identifier. Usually that is the id field, and will be in teh AccountsWhereUniqueInput type, but if userId is unique too, it can be tagged and will be part of the input type.
r
thats nice thats the strong typing of prisma catches this
l
Well, you may have an internal id (the id field), and an external id (username for example) , so not actually two entries, just different ways of identifiying the same.
r
i would have assumed that userId is already unique
l
Prisma can't guess what you think should be unique (in addition to the id field)
r
yeah I understand this