Prisma upsertmany issue Provided List<Json>,预期 SimilarCreateWithoutMovieInput
Prisma upsertmany issue Provided List<Json>, expected SimilarCreateWithoutMovieInput
使用"@prisma/client": "^2.25.0"
on prisma.upsertOneMovie. Provided List<Json>, expected SimilarCreateWithoutMovieInput or SimilarCreateWithoutMovieInput or SimilarUncheckedCreateWithoutMovieInput or SimilarUncheckedCreateWithoutMovieInput:
[0] type SimilarCreateWithoutMovieInput {
[0] id: Int
[0] backdrop_path: String
[0] title: String
[0] name: String
[0] release_date: DateTime
[0] overview: String
[0] show: TVShowCreateNestedOneWithoutSimilarInput
[0] }
代码
const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
...
let result = await apiRequest
let similar = result.similar.results.map(similar_movie => {
return {
id: similar_movie.id,
backdrop_path: similar_movie.backdrop_path,
title: similar_movie.title,
name: similar_movie.name,
release_date: similar_movie.release_date,
overview: similar_movie.overview,
movieId: result.id
}
})
const movie = {
id: result.id,
...
similar: {
upsert: similar
}
}
const upsertMovie = await prisma.movie.upsert({
where: { id: movie.id },
update: movie,
create: movie,
})
这里是 schema.prisma
model Movie {
id Int @id
...other fields and attributes...
similar Similar[]
}
model Similar {
id Int @id @default(autoincrement())
tmdb_id Int @unique
backdrop_path String
title String?
name String?
release_date String
overview String
movie Movie? @relation(fields: [movie_id], references: [id])
show TVShow? @relation(fields: [show_id], references: [id])
movie_id Int?
show_id Int?
}
Similar
应该是嵌套在特定 Movie
对象中的其他 Movies
的数组 []
,不能是它本身
我没有在生成类型上使用 prisma upsert 的经验,我收到了上述错误。我希望更新 Movie
并同时更新与 Movie
.
相关的 Similar
的多个记录
我试过使用 connectOrCreate
但它不支持创建 similar
的多条记录,同时按预期创建 movie
的一条记录
我该如何实现?
资源
https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#nested-writes
https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#connect-or-create-a-record
问题是 prisma createMany
在 sqlite 上不可用,而在 postgresql 连接器上可用。
const movie = {
...result,
similar: {
connectOrCreate: result.similar.map(s => ({
create: s,
where: { id: s.id },
}))
}
}
const upsertMovie = await prisma.movie.upsert({
where: { id: movie.id },
update: movie,
create: movie,
})
使用"@prisma/client": "^2.25.0"
on prisma.upsertOneMovie. Provided List<Json>, expected SimilarCreateWithoutMovieInput or SimilarCreateWithoutMovieInput or SimilarUncheckedCreateWithoutMovieInput or SimilarUncheckedCreateWithoutMovieInput:
[0] type SimilarCreateWithoutMovieInput {
[0] id: Int
[0] backdrop_path: String
[0] title: String
[0] name: String
[0] release_date: DateTime
[0] overview: String
[0] show: TVShowCreateNestedOneWithoutSimilarInput
[0] }
代码
const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
...
let result = await apiRequest
let similar = result.similar.results.map(similar_movie => {
return {
id: similar_movie.id,
backdrop_path: similar_movie.backdrop_path,
title: similar_movie.title,
name: similar_movie.name,
release_date: similar_movie.release_date,
overview: similar_movie.overview,
movieId: result.id
}
})
const movie = {
id: result.id,
...
similar: {
upsert: similar
}
}
const upsertMovie = await prisma.movie.upsert({
where: { id: movie.id },
update: movie,
create: movie,
})
这里是 schema.prisma
model Movie {
id Int @id
...other fields and attributes...
similar Similar[]
}
model Similar {
id Int @id @default(autoincrement())
tmdb_id Int @unique
backdrop_path String
title String?
name String?
release_date String
overview String
movie Movie? @relation(fields: [movie_id], references: [id])
show TVShow? @relation(fields: [show_id], references: [id])
movie_id Int?
show_id Int?
}
Similar
应该是嵌套在特定 Movie
对象中的其他 Movies
的数组 []
,不能是它本身
我没有在生成类型上使用 prisma upsert 的经验,我收到了上述错误。我希望更新 Movie
并同时更新与 Movie
.
Similar
的多个记录
我试过使用 connectOrCreate
但它不支持创建 similar
的多条记录,同时按预期创建 movie
的一条记录
我该如何实现?
资源
https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#nested-writes
https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#connect-or-create-a-record
问题是 prisma createMany
在 sqlite 上不可用,而在 postgresql 连接器上可用。
const movie = {
...result,
similar: {
connectOrCreate: result.similar.map(s => ({
create: s,
where: { id: s.id },
}))
}
}
const upsertMovie = await prisma.movie.upsert({
where: { id: movie.id },
update: movie,
create: movie,
})