Prisma: Prisma relations

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


Prisma relations solve a huge problem with databases and data handling.

Suppose you have a list of users in your app, that create tweets (imagine Twitter).

In your schema you can define the relation between those 2 entities in this way:

model Tweet {
  id Int @id @default(autoincrement()) 
  text String
  author User @relation(fields: [authorId], references: [id])
  authorId Int
}

model User {
  id Int @default(autoincrement()) @id
  tweets Tweet[]
}

When you create a new tweet you associate it with a user with id 1 in this way:

await prisma.tweet.create({
  data: {
    text: req.body.content,
    author: {
      connect: { id: 1 }
    }
  }
})

Then you can retrieve the author information when you get one tweet, with:

await prisma.tweet.findMany({
  include: {
    author: true
  }
})

You can also create a user and populate the database with 2 tweets associated to it:

await prisma.user.create({
  data: {
    tweets: {
      create: [
        { text: 'test' },
        { text: 'test2' },
      ]
    }
  }
})

Lessons in this unit:

0: Introduction
1: How to use Prisma
2: ▶︎ Prisma relations
3: Using multiple fields for a unique key in Prisma
4: Prisma, how to reverse order
5: Prisma, how to clear the database
6: How to solve the `prisma/client did not initialize yet` error on Vercel