.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
[ 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
github repo if needed: https://github.com/fejes99/MaterialPlanningApp/blob/main/main.wasp
GitHub
MaterialPlanningApp/main.wasp at main Β· fejes99/MaterialPlanningApp
Contribute to fejes99/MaterialPlanningApp development by creating an account on GitHub.
Oh, it seems like we might have a Wasp + Prisma problem on our hands.
Move the fields:
to be above the
reservations
field and it will stay in the Prisma schema properly β
Something like this:
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!Thanks for solution, i left the
?
accidentally.Thank you for the patience π let us know how's it going with the app when you have the chance!
I will, greetings!
Wohooo @david.fejes, you just became a Waspeteer level 2!