W
Wasp11mo ago
david.fejes

.wasp not recognising disambiguating relations

I have tried to define one-to-many relation between entities User and PurchaseRequest. Here is schema: entity User {=psl /// purchaseRequestsCreated PurchaseRequest[] @relation(name: "createdBy") purchaseRequestsProcessed PurchaseRequest[] @relation(name: "processedBy") psl=} entity PurchaseRequest {=psl /// author User @relation(name: "createdBy", fields: [authorId], references: [id]) authorId Int processedBy User @relation(name: "processedBy", fields: [processedById], references: [id]) processedById Int psl=} I have defined relation name following docs: https://www.prisma.io/docs/orm/prisma-schema/data-model/relations#disambiguating-relations But when i run wasp db migrate-dev i got error from comment. I realized that auto generated schema.prisma in .wasp/out/db does not contain @relation(name). After modifying that file and adding needed relations it works. I can't understand whether I made a mistake in defining the relationships or what is the reason why I can't define relationships within the WASP file so that they are successfully processed?
Prisma
Relations (Reference)
A relation is a connection between two models in the Prisma schema. This page explains how you can define one-to-one, one-to-many and many-to-many relations in Prisma.
7 Replies
david.fejes
david.fejesOP11mo ago
[ Db !] error: Error validating field author in model PurchaseRequest: The relation field author on model PurchaseRequest is missing an opposite relation field on the model User. Either run prisma format or add it manually. [ Db !] --> schema.prisma:105 [ Db !] | [ Db !] 104 | receiptDate DateTime? [ Db !] 105 | author User @relation(name: "createdBy", fields: [authorId], references: [id]) [ Db !] 106 | authorId Int [ Db !] | [ Db !] error: Error validating field processedBy in model PurchaseRequest: The relation field processedBy on model PurchaseRequest is missing an opposite relation field on the model User. Either run prisma format or add it manually. [ Db !] --> schema.prisma:107 [ Db !] | [ Db !] 106 | authorId Int [ Db !] 107 | processedBy User @relation(name: "processedBy", fields: [processedById], references: [id]) [ Db !] 108 | processedById Int [ Db !] | [ Db !] [ Db !] Validation Error Count: 2 [ Db !] [Context: getDmmf] [ Db !] [ Db !] Prisma CLI Version : 4.16.2
david.fejes
david.fejesOP11mo ago
GitHub
MaterialPlanningApp/main.wasp at main · fejes99/MaterialPlanningApp
Contribute to fejes99/MaterialPlanningApp development by creating an account on GitHub.
miho
miho11mo ago
Oh, it seems like we might have a Wasp + Prisma problem on our hands. Move the fields:
purchaseRequestsCreated ProductionPlanProducts[] @relation(name: "createdBy")
purchaseRequestsProcessed ProductionPlanProducts[] @relation(name: "processedBy")
purchaseRequestsCreated ProductionPlanProducts[] @relation(name: "createdBy")
purchaseRequestsProcessed ProductionPlanProducts[] @relation(name: "processedBy")
to be above the reservations field and it will stay in the Prisma schema properly ✅ Something like this:
entity User {=psl
id Int @id @default(autoincrement())
name String?
surrname String?
role String?
purchaseRequestsCreated ProductionPlanProducts[] @relation(name: "createdBy")
purchaseRequestsProcessed ProductionPlanProducts[] @relation(name: "processedBy")
reservations Reservation[]?
psl=}
entity User {=psl
id Int @id @default(autoincrement())
name String?
surrname String?
role String?
purchaseRequestsCreated ProductionPlanProducts[] @relation(name: "createdBy")
purchaseRequestsProcessed ProductionPlanProducts[] @relation(name: "processedBy")
reservations Reservation[]?
psl=}
If you move it below reservations it won't get passed into the schema 🤨 this is super weird, we'll investigate it and report back - Okay, one thing you have in your schema: reservations Reservation[]? is not supported by Prisma. Optional lists are not supported by Prisma, so, either it's a list or optional. - If you remove the ? the relationships you defined will work properly 😄 - Wasp should report this error to you, sorry for the missing diagnostics. We'll work on this in the future to make it easier to spot the issue!
david.fejes
david.fejesOP11mo ago
Thanks for solution, i left the ? accidentally.
miho
miho11mo ago
Thank you for the patience 🙂 let us know how's it going with the app when you have the chance!
david.fejes
david.fejesOP11mo ago
I will, greetings!
MEE6
MEE611mo ago
Wohooo @david.fejes, you just became a Waspeteer level 2!

Did you find this page helpful?