What you need here is connectOrCreate.
So something like this should work:
await prisma.post.create({
data: {
title: 'Hello',
categories: {
create: [
{
category: {
create: {
name: 'category-1',
},
},
},
{ category: { connect: { id: 10 } } },
],
},
},
});
You can also read more about this in the docs here
Answer from Ryan on Stack OverflowPrisma
prisma.io › home › relations › relations › relations › relations
Relations | Prisma Documentation
Relations in the Prisma schema represent relationships that exist between tables in the database.
Relations handling with explicit many to many relation
Hi, I’m using PlanetScale to ... with Prisma to build a simple API. I read the documentation about the things to consider, most notably the missing support of foreign keys. I followed the guide to create indexes on foreign keys and also the guide to create explicit many-to-many relations but then I ... More on github.com
Multiple relations to the same table
Hey guys! I need to build a table that has two references to the same table. The target table is User, the source table is Absence. The idea is that the Absence table has a reference to the user th... More on github.com
How to create multiple relationships to the same filed in prisma - Stack Overflow
You need to name the relations since you have two relations between same types (Driver <-> Shift and Driver <-> Zone both are connected by two relations each). In cases like this Prisma asks you to name the relations which is what the error message you posted is about. More on stackoverflow.com
database - Creating relationships in Prisma - Stack Overflow
I am creating a database with the help of Prisma and I have encountered a problem. I have 2 models: User and Lesson. In Lesson I store the IDs of the users who participated in it and the ID of the trainer, which is also a User model. I would like, when downloading Lesson, to be able to immediately get the users who took part in it and the trainer, but not their IDs, but the data of the whole user. I know I need a relationship... More on stackoverflow.com
14:47
Prisma Tutorial for Beginners #9 - One-to-Many Relations - YouTube
11:40
Mastering Prisma in Next.js: One-to-Many Relationships - YouTube
15:24
Mastering Prisma in Next.js: Explicit Many-to-Many Relationships ...
26:32
Learn Prisma Relationships (1-1, 1-m, m-m) - YouTube
Prisma で many to many のリレーションシップを定義する
15:20
Opposite Relation Fields | Express API & Prisma ORM Query ...
Top answer 1 of 5
25
What you need here is connectOrCreate.
So something like this should work:
await prisma.post.create({
data: {
title: 'Hello',
categories: {
create: [
{
category: {
create: {
name: 'category-1',
},
},
},
{ category: { connect: { id: 10 } } },
],
},
},
});
You can also read more about this in the docs here
2 of 5
8
After hours of trying I finally came up with the following solution for my use case.
park[] <-> exercise[]
// create parks
const parks = await prisma.park.createMany({data: [...]});
// create and connect exercises
const exercises = [...];
await Promise.all(
exercises.map(async (exercise) => {
await prisma.exercise.create({
data: <any>{
...exercise,
parks: {
connect: parks.map((park) => ({ id: park.id })),
},
},
});
}),
);
Top answer 1 of 3
8
You need to name the relations since you have two relations between same types (Driver <-> Shift and Driver <-> Zone both are connected by two relations each).
In cases like this Prisma asks you to name the relations which is what the error message you posted is about. I think this data model should work:
type Driver {
id: ID! @unique
zones: [Zone!] @relation(name: "DriverZones")
shifts: [Shift!] @relation(name: "DriverShifts")
preferredZone: Zone @relation(name: "PreferredZone")
preferredShift: Shift @relation(name: "PreferredShift")
}
type Shift {
id: ID! @unique
drivers: [Driver! ] @relation(name: "DriverShifts")
}
type Zone {
id: ID! @unique
drivers: [Driver! ] @relation(name: "DriverZones")
}
2 of 3
0
I would like you to try this way:
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accountId String @unique
account Account @relation(fields: [accountId], references: [id])
sessions Session[]
TeamHasMembers TeamHasMembers[]
TeamHasLeaders TeamHasLeaders[]
}
model Team {
id String @id @default(cuid())
name String
slug String @unique
TeamHasMembers TeamHasMembers[]
TeamHasLeaders TeamHasLeaders[]
}
model TeamHasMembers {
id String @id @default(cuid())
userId String
teamId String
role String
user User @relation(fields: [userId], references: [id])
team Team @relation(fields: [teamId], references: [id])
}
model TeamHasLeaders {
id String @id @default(cuid())
userId String
teamId String
user User @relation(fields: [userId], references: [id])
team Team @relation(fields: [teamId], references: [id])
}
VOSviewer
vosviewer.com
VOSviewer - Visualizing scientific landscapes
VOSviewer is a software tool for constructing and visualizing bibliometric networks.
Lippincott Williams & Wilkins
journals.lww.com › indianjpsychiatry › fulltext › 2026 › 04000 › global_and_regional_level_association_between.1.aspx
Global and regional level association between depression... : Indian Journal of Psychiatry
Furthermore, synthesizing data on the depression and its relationship with glycemic control at both global and regional levels is critical to generate evidence that informs targeted and effective interventions. We aimed to investigate the global and regional level association between depression and glycemic control in T2DM. The current “Systematic Review and Meta-analysis (SRMA)” adhered to the “Preferred Reporting Items for Systematic Reviews and Meta-Analyses 2020 (PRISMA)” guidelines.
GitHub
github.com › prisma › prisma › discussions › 17823
Using "where" in many-to-many relation · prisma/prisma · Discussion #17823
December 9, 2023 - Trying to figure out how could I get Categories with Expenses created at specific date, any suggestions? Below my prisma schema : It should look something like this, but "where" is not wo...
Author prisma
npm
npmjs.com › package › prisma-generator-typescript-interfaces
prisma-generator-typescript-interfaces - npm
September 4, 2025 - Generate zero-dependency TypeScript interfaces from Prisma schema. Latest version: 3.1.0, last published: 9 months ago. Start using prisma-generator-typescript-interfaces in your project by running `npm i prisma-generator-typescript-interfaces`. There are 0 other projects in the npm registry using prisma-generator-typescript-interfaces.
» npm install prisma-generator-typescript-interfaces
Published Sep 04, 2025
Version 3.1.0

