PrismaP
Prisma2y ago
3 replies
Virtus

ID needed in delete()?

I'm using Postgres and have a schema for Discord Members. To make it simple with join tables, the primary key (named sid) of the table is an auto-incrementing integer, then another unique index care of the guild ID and user ID combo.
model DiscordMembers {
  sid                           Int @id @default(autoincrement())

  id                            String @db.VarChar(20)
  guild_id                      String @db.VarChar(20)
  nick                          String? @db.VarChar(32)
  avatar                        String? @db.VarChar(34) /// 32 + a_ for animated
  joined_at                     DateTime @db.Timestamptz(6)
  premium_since                 DateTime? @db.Timestamptz(6)
  deaf                          Boolean?
  mute                          Boolean?
  flags                         Int?
  pending                       Boolean?
  permissions                   BigInt?
  communication_disabled_until  DateTime? @db.Timestamptz(6)
  created_at                    DateTime @default(now()) @db.Timestamptz(6)
  updated_at                    DateTime? @updatedAt @db.Timestamptz(6)

  user                          DiscordUsers @relation(fields: [id], references: [id])

  roles                         DiscordMemberRoles[]

  // Unique index combination of guild_id and id
  @@unique([guild_id, id], map: "user_id_in_guild")
  @@map("DiscordMembers")
}


When I then want to delete a member, I do not use the sid at all, since I also don't know what it would be without first querying it. So I use the unique guild ID and user ID combination
await this.DiscordMembers.delete({
    where: {
        guild_id: guildId,
        id: userId,
    }
});

However TypeScript is now throwing a fit because sid is required. Am I using this wrong or what's going on here?
image.png
Was this page helpful?