Commit 6d771d1
Fix regression: list-only many-to-many relationships not generating synthetic back-reference fields (#356)
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
Co-authored-by: Claude <noreply@anthropic.com>1 parent cf3bca4 commit 6d771d1
3 files changed
Lines changed: 59 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
322 | 357 | | |
323 | 358 | | |
324 | 359 | | |
| |||
999 | 1034 | | |
1000 | 1035 | | |
1001 | 1036 | | |
1002 | | - | |
| 1037 | + | |
1003 | 1038 | | |
1004 | 1039 | | |
1005 | 1040 | | |
| |||
1022 | 1057 | | |
1023 | 1058 | | |
1024 | 1059 | | |
1025 | | - | |
1026 | | - | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
1027 | 1066 | | |
1028 | 1067 | | |
1029 | 1068 | | |
| |||
1248 | 1287 | | |
1249 | 1288 | | |
1250 | 1289 | | |
1251 | | - | |
| 1290 | + | |
1252 | 1291 | | |
1253 | | - | |
1254 | | - | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
1255 | 1296 | | |
1256 | 1297 | | |
1257 | 1298 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
411 | 412 | | |
412 | | - | |
| 413 | + | |
| 414 | + | |
413 | 415 | | |
414 | 416 | | |
415 | 417 | | |
| |||
0 commit comments