Hello, I'm wondering when you do a nested `connect...
# orm-help
j
Hello, I'm wondering when you do a nested
connect
is the relationship supposed to connect both ways? Right now a
create
that I'm using is connecting the parent to the child but is not creating a connection from the child to the parent.
Copy code
await prisma.game.create({
        data: {
          ...,
          Team_Game_blueTeamToTeam: {
            create: {
              teamId: match.info.teams.filter((p) => p.teamId === 100)[0]
                .teamId,
              win: match.info.teams.filter((p) => p.teamId === 100)[0].win,
              teamMatchId: `${match.metadata.matchId}_blue`,
              Player: {
                connectOrCreate: match.info.participants
                  .filter((p) => p.teamId === 100)
                  .map((p) => ({
                    where: { puuid: p.puuid },
                    create: {
                      puuid: p.puuid,
                    },
                  })),
              },
              ...,
            },
          },
          ...,
        },
      });
In my example
game
has a connection to
team
but
team
doesn't have a connection back to
game
.
Copy code
model Game {
  id                       String                @id @default(cuid())
  matchId                  String                @unique @default("")
  gameId                   String                @default("")
  gameCreation             String                @default("")
  gameStartTimestamp       String                @default("")
  gameEndTimestamp         String                @default("")
  duration                 Int?
  start                    String                @default("")
  gameVersion              String                @default("")
  blueTeam                 String?
  redTeam                  String?
  tournament               String                @default("")
  gameInSeries             Int?
  vod                      String                @default("")
  platformId               String                @default("")
  Team_Game_blueTeamToTeam Team?                 @relation("Game_blueTeamToTeam", fields: [blueTeam], references: [id])
  Team_Game_redTeamToTeam  Team?                 @relation("Game_redTeamToTeam", fields: [redTeam], references: [id])
  PlayerEndOfGameStat      PlayerEndOfGameStat[]
  Team_GameToTeam_game     Team[]                @relation("GameToTeam_game")
  Source                   Source[]              @relation("Game_source")

  @@index([blueTeam])
  @@index([redTeam])
}
a
Hey Jeremiah 👋, Could you share the
Team
side of your schema as well?
j
Yes, it looks like this:
Copy code
model Team {
  id                       String      @id @default(cuid())
  game                     String?
  teamId                   Int?
  teamMatchId              String      @unique @default("")
  win                      Boolean     @default(false)
  Game_GameToTeam_game     Game?       @relation("GameToTeam_game", fields: [game], references: [id])
  Game_Game_blueTeamToTeam Game[]      @relation("Game_blueTeamToTeam")
  Game_Game_redTeamToTeam  Game[]      @relation("Game_redTeamToTeam")
  Objective                Objective[]
  PickBan                  PickBan[]
  Player                   Player[]    @relation("Player_teams")

  @@index([game])
}
n
Hey Jeremiah 👋 connect would just connect a record one way if you are maintaining foreign keys on both sides of tables, you would need to connect the record other way around as well.