Fix synthetic back-reference generation for list-only relationships#356
Merged
Fix synthetic back-reference generation for list-only relationships#356
Conversation
…ynthetic back-reference fields
In 0.19.0, a change to the synthetic field generation condition (from
`joinTableNaming !== 'keystone'` to `!m2mCheck.isManyToMany`) fixed
one-sided many-to-one relationships with Keystone naming but accidentally
broke list-only many-to-many relationships.
Prisma requires both sides of any implicit many-to-many relationship to be
defined. Without the synthetic back-reference field on the target model,
Prisma throws a 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`.
Fix: always generate synthetic back-reference fields for list-only refs
(no `targetField`), regardless of whether the relationship is many-to-many
or many-to-one. The relation name now correctly uses `db.relationName` when
explicitly set, falling back to the auto-generated `${listName}_${fieldName}`.
Updates two incorrect tests that asserted synthetic fields were NOT generated
for list-only many-to-many (both with Keystone naming and explicit relationName),
and adds a dedicated regression test matching the reported bug scenario.
https://claude.ai/code/session_01TQUjki3U3XpDWmvU3AbYNr
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 059acd1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Coverage Report for Core Package Coverage (./packages/core)
File CoverageNo changed files found. |
Contributor
Coverage Report for UI Package Coverage (./packages/ui)
File CoverageNo changed files found. |
Contributor
Coverage Report for CLI Package Coverage (./packages/cli)
File Coverage
|
||||||||||||||||||||||||||||||||||||||
Contributor
Coverage Report for Auth Package Coverage (./packages/auth)
File CoverageNo changed files found. |
Contributor
Coverage Report for Storage Package Coverage (./packages/storage)
File CoverageNo changed files found. |
Contributor
Coverage Report for RAG Package Coverage (./packages/rag)
File CoverageNo changed files found. |
Contributor
Coverage Report for Storage S3 Package Coverage (./packages/storage-s3)
File CoverageNo changed files found. |
Contributor
Coverage Report for Storage Vercel Package Coverage (./packages/storage-vercel)
File CoverageNo changed files found. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #355
Summary
This PR fixes a regression in version 0.19.0 where list-only relationships (both many-to-many and many-to-one) stopped generating required synthetic back-reference fields on the target model. This caused Prisma schema validation errors because Prisma requires both sides of any relationship to be explicitly defined.
Key Changes
prisma.tsto always generate synthetic back-reference fields for list-only relationships, regardless of whether they are many-to-many or many-to-onerelField.db?.relationName, falling back to auto-generated names otherwiseImplementation Details
The fix removes the condition that excluded many-to-many relationships from synthetic field generation. The key insight is that Prisma's implicit many-to-many relationships still require both sides to be explicitly defined in the schema, even though Prisma handles the join table implicitly. The synthetic field generation now applies consistently to all list-only references, using either the explicit relation name (if provided) or an auto-generated one based on the source model and field name.
https://claude.ai/code/session_01TQUjki3U3XpDWmvU3AbYNr