ezeikel
11/09/2021, 3:35 PMcreateMany
but also wanted to create new records in the contributions
table to record which user uploaded the media. I noticed trying to use create
for the nested relation doesn't work as it does in other cases. And I think these docs are saying that you can't access relations inside of a createMany
- https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#create-multiple-records-and-multiple-related-records
So my question is what would the alternative/workaround way to do this?
createMany: {
data:
processedMedia?.map(singleProcessedMedia => ({
...singleProcessedMedia,
contribution: {
create: {
type: "MEDIA",
user: {
connect: {
id: userId,
},
},
},
},
})) || [],
},
ezeikel
11/09/2021, 3:51 PMcreate
insteadStephen Osei-Bonsu
11/10/2021, 2:26 PMezeikel
11/10/2021, 2:39 PMmedia: {
connect:
existingMedia?.map(singleMedia => ({
id: singleMedia.id,
})) || [],
create:
processedMedia?.map(singleProcessedMedia => ({
...singleProcessedMedia,
contribution: {
create: {
type: "MEDIA" as ContributionType, // TODO: why do i need to cast this?
user: {
connect: {
id: userId,
},
},
},
},
})) || [],
},