Carlos
12/30/2021, 3:15 AMconst createUserAndPost = await prisma.user.create({
data: {
email: ‘elsa@prisma.io’,
name: ‘Elsa Prisma’,
posts: {
create: [
{ title: ‘How to make an omelette’ },
{ title: ‘How to eat an omelette’ },
],
},
},
})
In this example, I would like to create none, one or more post. So how do I handle if there are no post to create? How can I tell prisma to not throw any errors?Alex Ruheni
createMany
doesn’t work with nested relations. In this case, I’d recommend using create
which we use in the seed file in the prisma-examples
:
https://github.com/prisma/prisma-examples/blob/latest/typescript/graphql-fastify/prisma/seed.ts#L5-L62