Hello everyone, Does anybody know if it is possib...
# orm-help
c
Hello everyone, Does anybody know if it is possible to use an optional nested createMany?
const 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?
a
Hi Carlos 👋🏽
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