david.fejes
WWasp-lang
•Created by david.fejes on 3/13/2024 in #đŸ™‹questions
.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?11 replies
WWasp-lang
•Created by david.fejes on 3/12/2024 in #đŸ™‹questions
Object relation doesn't compile to TypeScript
I have an explicit many-to-many relation that I want to display data. After migrating from version 0.11 to version 0.12, I can't find a way to display objects of my entity. Here is my schema:
entity Material {=psl
id Int @id @default(autoincrement())
code String @unique
name String
count Int
measurementUnit String
products ProductMaterials[]
psl=}
entity ProductMaterials {=psl
product Product @relation(fields: [productId], references: [id])
productId Int
material Material @relation(fields: [materialId], references: [id])
materialId Int
materialCount Int
measurementUnit String
@@id([productId, materialId])
psl=}
entity Product {=psl
id Int @id @default(autoincrement())
code String @unique
name String
description String
materials ProductMaterials[]
productionPlans ProductionPlanProducts[]
psl=}
When i try to display products for material error occurs: Property 'products' does not exist on type 'GetResult<{ id: number; code: string; name: string; count: number; measurementUnit: string; }, unknown> & {}'.
Since I have migrated from an old version of Wasp, in which my code works, I'm curious about what makes the difference that in the previous version, the import from @wasp/entities
includes objects of entities, and in the new version, the import from wasp/entities
doesn't include them.
I have found a previous post and solution which includes creating a new type. Is there any way to include objects with types from prisma/entities
?10 replies
WWasp-lang
•Created by david.fejes on 3/11/2024 in #đŸ™‹questions
After migration flowbite-react is not working
7 replies