per
08/16/2021, 10:38 AMRyan
08/16/2021, 10:46 AMplayer2
if optional will return null
if not present.per
08/16/2021, 10:49 AMteam
table, player2
is optional but as soon as I use this query with a team that doesnt have a player2
I get an error.
And thank you so much for replying 👋Ryan
08/16/2021, 10:54 AMper
08/16/2021, 10:57 AMper
08/16/2021, 10:58 AMper
08/16/2021, 10:59 AMper
08/16/2021, 11:03 AMgroup
table?Ryan
08/16/2021, 11:07 AMRyan
08/16/2021, 11:08 AMis a GroupMemberships table even needed or should I put the teamrelation in theDo you need to add extra fields about the membership? If so, then let the explicit model be as it is. If not, then you can directly addtable?group
Group
to Team
.per
08/16/2021, 11:11 AMRyan
08/16/2021, 11:16 AMper
08/16/2021, 11:17 AMper
08/16/2021, 11:21 AMper
08/16/2021, 11:22 AMper
08/16/2021, 11:22 AMRyan
08/16/2021, 11:22 AMit’s just my api call that fails and it doesn’t as long as I dont request something that doesnt exist (edited)Can you log the error in the
catch
block of your API and share it here? The issue might be something else.Ryan
08/16/2021, 11:23 AMgroups
and teams
as this is a many-to-many relation.per
08/16/2021, 11:24 AMRyan
08/16/2021, 11:24 AMper
08/16/2021, 11:24 AMper
08/16/2021, 11:33 AMRyan
08/16/2021, 11:37 AMper
08/16/2021, 11:39 AMper
08/16/2021, 11:42 AMper
08/16/2021, 11:42 AMper
08/16/2021, 11:42 AMRyan
08/16/2021, 11:43 AMteamId
. That can be removed.per
08/16/2021, 11:44 AMfields
per
08/16/2021, 11:45 AMRyan
08/16/2021, 11:46 AM@relation
is also optional and can be removed 🙂per
08/16/2021, 11:47 AMRyan
08/16/2021, 11:47 AMmodel Player {
id String @id @default(cuid())
name String
email String? @unique
profilePic String?
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @updatedAt @map(name: "updated_at")
player1 Team[] @relation("player1")
player2 Team[] @relation("player2")
}
model Team {
id String @id @default(cuid())
player1Id String
player2Id String?
groupId String
player1 Player @relation("player1", references: [id], fields: [player1Id])
player2 Player? @relation("player2", references: [id], fields: [player2Id])
groups Group[]
}
model Group {
id String @id @default(cuid())
name String
teams Team[]
}
per
08/16/2021, 11:48 AMper
08/16/2021, 11:52 AMper
08/16/2021, 11:53 AMconst teamsTest = await prisma.group.findMany({
where: { id: context.query.id as string },
include: { teams: true },
})
per
08/16/2021, 11:53 AMper
08/16/2021, 11:56 AMper
08/16/2021, 11:59 AMplayer2
workper
08/16/2021, 12:00 PMper
08/16/2021, 12:04 PMper
08/16/2021, 12:04 PMper
08/16/2021, 12:05 PMplayer1
and player2
where the id is nested. I dont need player1id explicitRyan
08/16/2021, 12:20 PMselect
with only the necessary fields should work here.per
08/16/2021, 12:20 PMper
08/16/2021, 12:21 PMper
08/16/2021, 12:21 PMRyan
08/16/2021, 12:21 PMctrl+space
inside the arguments will let you know all the options that you can pass.per
08/16/2021, 12:22 PMper
08/16/2021, 12:27 PMRyan
08/16/2021, 12:29 PMper
08/16/2021, 12:29 PM