-
-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Summary
In OpenSaaS Stack 0.18.x, a relationship({ ref: 'User', many: true }) field (many-to-many with only one side defined) would automatically generate an implicit back-reference field on the related model. In 0.19.0, this auto-generation has stopped, causing a Prisma schema validation error.
Regression
0.18.x behaviour (working)
Given:
// textMessage.ts
readBy: relationship({
ref: 'User',
many: true,
})The generator produced in schema.prisma:
model TextMessage {
readBy User[] @relation("TextMessage_readBy")
}
model User {
readByMessages TextMessage[] @relation("TextMessage_readBy") // auto-generated back-ref
}0.19.0 behaviour (broken)
Same config now produces:
model TextMessage {
readBy User[] @relation("TextMessage_readBy")
}
model User {
// readByMessages field is MISSING
}This triggers a Prisma validation error:
Error validating field `readBy` in model `TextMessage`: The relation field `readBy` on model `TextMessage`
is missing an opposite relation field on the model `User`.
Either run `prisma format` or add it manually.
Steps to Reproduce
- Create a list with a many-to-many relationship where only one side is defined:
const TextMessage = list({ fields: { readBy: relationship({ ref: 'User', many: true }), }, })
- Run
opensaas generate - Observe Prisma validation error
Expected Behaviour
Either:
- Restore the auto-generated back-reference: The generator should add an implicit
from_<List>_<field>back-reference field on the related model (as 0.18.x did), or - Document the breaking change: If the new behaviour intentionally requires explicit back-refs on both sides, document the migration path with a clear error message like "Relationship
readByis many-to-many butUserhas no back-reference field pointing toTextMessage.readBy"
Additional Context
- This affects any migration from Keystone 6 where many-to-many relationships had only one side defined (Keystone 6 similarly auto-generated back-references)
- Workaround: explicitly define the back-ref field on the related model AND update the
refto point to it
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels