Prisma Relationships

In today's lecture, Harkirat provided a comprehensive Recap of Prisma, focusing on the framework's approach to defining and managing relationships within a database schema. He also explains the significance of the Prisma Client in facilitating database operations and the role of Prisma's migration system in tracking and applying schema changes.

Relationships

In Prisma, relationships between tables are defined using a straightforward and expressive syntax within the Prisma schema file. These relationships are crucial for representing how data in one table is associated with data in another, and Prisma supports several types of relationships to model the various ways in which data can be interconnected.

Untitled

Types of Relationships in Prisma

Prisma allows you to define the following types of relationships:

  1. One to One: A relationship where a single record in one table is linked to a single record in another table.
  2. One to Many: A relationship where a single record in one table is linked to multiple records in another table.
  3. Many to One: The inverse of one to many, where multiple records in one table are linked to a single record in another table.
  4. Many to Many: A relationship where multiple records in one table are linked to multiple records in another table.

One to Many Relationship in the TODO App

For the TODO app, there is a one-to-many relationship between the User and Todo models. This means that one user can have many todos, but each todo is associated with only one user.