Hey all :wave: I was trying to allow a user to upl...
# orm-help
e
Hey all 👋 I was trying to allow a user to upload multiple images/video aka media so wanted to use
createMany
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?
Copy code
createMany: {
            data:
              processedMedia?.map(singleProcessedMedia => ({
                ...singleProcessedMedia,
                contribution: {
                  create: {
                    type: "MEDIA",
                    user: {
                      connect: {
                        id: userId,
                      },
                    },
                  },
                },
              })) || [],
          },
Just realised I can just pass an array to
create
instead
💯 1
s
Can You send me a screen shot of how you're doing this, maybe I can apply it on my case. I was trying the array with create() but wasn't working
e
Copy code
media: {
          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,
                    },
                  },
                },
              },
            })) || [],
        },