Hey all, this might sound silly, but slightly conf...
# orm-help
d
Hey all, this might sound silly, but slightly confused. So I am using Prisma with a Discord.JS bot, and currently I am working on a faction-based bot, and so far Prisma has been an absolute delight to work with compared to other ORM's I have used with TypeScript. I am currently stuck with a where clause, primarily, I am working with two models, where I have my faction, that then contains a list of faction channels as a relation many to one, so many channels can be assigned to a single faction, but a single channel would not be linked to many factions. Faction Model
Copy code
model Faction {
  id          String           @id @default(dbgenerated()) @map("_id") @db.ObjectId
  name        String
  roleId      String
  image       String           @default("#000000")
  description String           @default("No description has been set.")
  colour      String?
  rules       String           @default("No rules have been set.")
  channels    FactionChannel[]
  categoryId  String
  owner       User             @relation(name: "OwnedFactions", fields: [ownerId], references: [id])
  ownerId     String
  admins      String[]
  members     String[]
  guildId     String
  balance     Int              @default(0)
  wins        Int              @default(0)
  losses      Int              @default(0)
  draws       Int              @default(0)
  warnings    FactionWarning[]
  bans        FactionBan[]
  created     DateTime         @default(now())
  updated     DateTime         @updatedAt
  audit       FactionAudit[]
}
Faction Channel Model
Copy code
model FactionChannel {
  id         String             @id @default(dbgenerated()) @map("_id") @db.ObjectId
  discordId  String             @unique
  name       String
  type       FactionChannelType @default(TEXT)
  isCategory Boolean            @default(false)
  faction    Faction            @relation(fields: [factionId], references: [id])
  factionId  String
  claimable  Boolean            @default(false)
  admin      Boolean            @default(false)
}
So far, all is working fine, I have created two factions with 4 channels each, and this seems to work nicely, but I am trying to figure out how to query the faction based on where a certain channel exists, for example, if a user in a specific discord channel wants to know more about the faction like it's monetary balance, or it's total wins, I need to be able to lookup the faction based on the channel they are in, so at the moment, I have done:
Copy code
const faction = await this.prisma.faction.findFirst({
  where: {
    channels: {
      some: {
        discordId: channelId,
      },
    },
  },
});
The above is failing to return any results, even though the channel IS part of the faction. Any ideas what I am doing wrong here, help would be appreciated.