Menu

Post image 1
Post image 2
1 / 2
0

Prisma relationships, finally explained (with MySQL side by side)

DEV Community·Mohamed Idris·24 days ago
#UeqUETUf
#prisma#er#mysql#querying#user#userid
Reading 0:00
15s threshold

If Prisma relationships feel like a maze, this post is for you. We are going to build the data model for a small job posting app and walk through every kind of relationship, side by side with MySQL and a quick ER diagram for each one. You already know MySQL and ER diagrams. The goal here is not to teach you what a foreign key is. The goal is to make Prisma's syntax click so you stop guessing where to put what. The one idea that fixes everything Most people get stuck because Prisma asks you to declare a relationship on both models . That looks redundant, like you are saying the same thing twice. You are not. Here is the rule that unlocks the whole thing: The foreign key column lives on exactly one side. Both models name each other so Prisma can see the link in both directions. In MySQL you only write the foreign key once, on the table that holds it. Prisma still does that, but it also asks the other table to name the relationship from its point of view, just for the JavaScript side.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More