Upsert: Help in finalizing the command, gettings two errors

Viewed 16

My models:

    model Show {
  id        Int      @id @default(autoincrement())
  tvmazeId  Int
  name      String
  type      Type     @relation(fields: [typeId], references: id) 
  typeId    Int
  language  Language @relation(fields: [languageId], references: id)
  languageId  Int
  genres    GenresOnShows[]
  status    Status   @relation(fields: [statusId], references: id)
  statusId  Int
  runtime   Int?
  premiered DateTime?
  ended     DateTime?
  network   Network?   @relation(fields: [networkId], references: id)
  country   Country?   @relation(fields: [countryId], references: id)
  countryId  Int
  networkId  Int
  webchannel  Webchannel?   @relation(fields: [webchannelId], references: id)
  webchannelId  Int
  tvrageId  String? @unique
  thetvdbId String? @unique
  imdbId    String? @unique
  imageMed  String? @unique
  imageOrig String? @unique
  summary   String

}

model Status {
  id        Int      @id @default(autoincrement())
  name      String   @unique
  shows     Show[]
}

model Type {
  id        Int      @id @default(autoincrement())
  name      String   @unique
  shows     Show[]
}

model Language {
  id        Int      @id @default(autoincrement())
  name      String   @unique
  shows     Show[]
}


model Country {
  id        Int      @id @default(autoincrement())
  name      String   @unique
  code      String   @unique
  timezone  String
  shows     Show[]
}

model Network {
  id        Int      @id @default(autoincrement())
  name      String   @unique
  shows     Show[]
}

model Webchannel {
  id        Int      @id @default(autoincrement())
  name      String   @unique
  shows     Show[]
}

model Genre {
  id        Int      @id @default(autoincrement())
  name      String   @unique
  shows     GenresOnShows[]
}

model GenresOnShows {
  show       Show     @relation(fields: [showId], references: [id])
  showId     Int 
  genre      Genre     @relation(fields: [genreId], references: [id])
  genreId     Int 
  @@id([showId, genreId])
}

What i try is getting show information from an api and populate the database. The problem is, that i need to populate related tables (like network, country, etc.) in the same action.

Here is how i get for example the country:

            const country = await prisma.country.upsert(
            {
                where: {
                    name: show["network"]["country"]["name"]
                },
                update: {},
                create: {
                    name: show["network"]["country"]["name"],
                    code: show["network"]["country"]["code"],
                    timezone: show["network"]["country"]["timezone"],
                }
            }
        )

and heres the statement i use to try to update the show:

        const showInDb = await prisma.show.upsert(
            {
                where: {
                    tvmazeId: show["id"]
                },
                update: {
                    typeId: {connect: {type}},
                    languageId: {connect: {language}},
                    genreConnectOrCreate: genreConnectOrCreate,
                    statusId: {connect: {status}},
                    networkId: {connect: {network}},
                    countryId: {connect: {country}}, 
                    webchannelId: {connect: {webchannel}},
                    name: show["name"],
                    runtime: parseInt(show["runtime"]),
                    premiered: new Date(show["premiered"]),
                    ended: new Date(show["ended"]),
                    tvrageId: show["externals"]["tvrage"].toString(),
                    tvdbId: show["externals"]["thetvdb"],
                    imdbId: show["externals"]["imdb"],
                    tvmazeId: show["id"],
                    imageMed: show["image"]["medium"],
                    imageOrig: show["image"]["original"],
                    summary: show["summary"]
                },
                create: {
                    typeId: {connect: {type}},
                    languageId: {connect: {language}},
                    genreConnectOrCreate: genreConnectOrCreate,
                    statusId: {connect: {status}},
                    networkId: {connect: {network}},
                    countryId: {connect: {country}}, 
                    webchannelId: webchannel,
                    name: show["name"],
                    runtime: parseInt(show["runtime"]),
                    premiered: new Date(show["premiered"]),
                    ended: new Date(show["ended"]),
                    tvmazeId: show["id"],
                    tvrageId: show["externals"]["tvrage"].toString(),
                    tvdbId: show["externals"]["thetvdb"],
                    imdbId: show["externals"]["imdb"],
                    imageMed: show["image"]["medium"],
                    imageOrig: show["image"]["original"],
                    summary: show["summary"]
                }
            }
        )

I tried with the ID (for example countryId aswell as country itself). The error i get when using countryId is: Unknown arg countryId in update.countryId for type ShowUpdateInput. Did you mean country?

if i use country: Unknown arg country in update.country.connect.country for type CountryWhereUniqueInput. Did you mean code?

I also tried to privde the country without the connect like so: country: country,

what is the correct way to do that?

0 Answers
Related