jasci
06/01/2021, 8:36 AMparentSalesDomain
How model looks before the last step of the upgrade CLI
model Calendar {
id String @id @default(cuid()) @db.VarChar(30)
...
parentSalesDomain String? @db.VarChar(30)
SalesDomain SalesDomain? @relation(fields: [parentSalesDomain], references: [id])
...
}
How model looks after the last step of the upgrade CLI
model Calendar {
id String @default(cuid()) @id @db.VarChar(30)
...
parentSalesDomainId String? @map("parentSalesDomain") @db.VarChar(30)
parentSalesDomain SalesDomain? @relation(fields: [parentSalesDomain], references: [id])
...
}
I cannot quite understand:
1. Is it allowed for the fields field of the relation attribute to reference itself ?
2. What is the role of the @map attribute here ? We map it to the underlying foreign key and then don't use this field in the relation
What I think it should look like. I'm gonna use the new schema to create a new db from it, so I can rename fields(foreign key before - parentSalesDomain, foreign key now - parentSalesDomainId). Is it the right model definition?
model Calendar {
id String @id @default(cuid()) @db.VarChar(30)
...
parentSalesDomainId String @db.VarChar(30)
parentSalesDomain SalesDomain @relation(fields: [parentSalesDomainId], references: [id])
...
}
Thank you.
P.S.
prisma1 schema
type Calendar {
id: ID! @id
...
parentSalesDomain: SalesDomain!
...
}nikolasburk
Is it allowed for theĀNo, this is not allowed, it's a bug in the Upgrade CLI if it produced this.Ā field of theĀfieldsĀ attribute to reference itself ?relation
What is the role of theĀYes, the field is being mapped to the underlying FK š here is what this relation is supposed to look like:Ā attribute here ? We map it to the underlying foreign key and then don't use this field in theĀ@maprelation
model Calendar {
id String @default(cuid()) @id @db.VarChar(30)
...
parentSalesDomainId String? @map("parentSalesDomain") @db.VarChar(30)
parentSalesDomain SalesDomain? @relation(fields: [parentSalesDomainId], references: [id])
...
}jasci
06/01/2021, 3:08 PM