Danny SMc
12/30/2021, 5:39 PMmodel 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
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:
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.