bb2021
06/19/2021, 5:06 AMupsert
and connectOrCreate
somehow incompatible? 🤔
i've got something along the lines of:
const director = someBoolean ? { connectOrCreate: { create: { name: 'Steven Spielberg' }, where: { name: 'Steven Spielberg' } } } : undefined
const movie = { contentId: 'some_id_here', title: 'Jaws', director }
const upsertResult = await prisma.movie.upsert({ create: movie, update: movie, where: { contentId: movie.contentId } })
// results in "The change you are trying to make would violate the required relation 'DirectorToMovie' between the 'Director' and 'Movie' models.
for reference, the Movie model lists a director as being optional, which is why I'm so confused at it complaining that it would break a required relation. Not sure if it's important, but I'm using sqlite as the underlying db
model Movie {
id Int @id @default(autoincrement())
contentId String
title String
director Director?
}
model Director {
id Int @id @default(autoincrement())
name String @unique
movie Movie @relation(fields: [movieId], references: [id])
movieId Int
}
Ryan
06/22/2021, 6:22 AMMovie
lists that as optional, but the movie
is required in Director
. Could you try making that optional and then check?