Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prisma CreateMany with Connect

Tags:

node.js

prisma

in Prisma is there a way to createMany with a connect?

Basically this a million times:

I read the documentation and there doesn't seem to be "nested createMany" but i think that's not that im doing (FWIW my code below wasn't able to be found in documentation either...)

    const result = await prisma.posts.create({
      data: {
        user: {
          connect: {
            id: user.id,
          },
        },
        ...postData,
      },
    });
like image 794
fotoflo Avatar asked Oct 25 '25 07:10

fotoflo


1 Answers

Ok I found that this was actually quite simple... just do it as usual insert and include the forign key id.

    const result = await prisma.posts.createMany([
      {
        ...postData,
       userId,
      },
    ]);
like image 50
fotoflo Avatar answered Oct 26 '25 21:10

fotoflo