Update userId which is used for defining relationships between models

Hey. I’ve got in the situation where I need to replace userIds of a user, that define many relationships, like student-to-teacher, teacher-to-students, students-to-lessons. Obviously, I tried the most forward way of just looking for specific userId across the tables and having it replaced with the new one, but prisma quickly throws an error signifying that I try to push changes that would violate above-mentioned relationships. Any guidance will be really appreciated.
3 Replies
oadster
oadster11mo ago
If I had to guess when you defined the relations you don't have something like cascade between them so if you change the userId you would need the changes to be cascaded to the other relationships
oadster
oadster11mo ago
Prisma
Referential actions
Referential actions let you define the update and delete behavior of related models on the database level
.traevelliath
.traevelliath11mo ago
I had to define onUpdate only on self-relations (teacher-students and student-teacher). So when I try to change first the id of the teacher then look for an old id in teacherId records, prisma throws an error saying that I violate self-relation.