Repository navigation
Conversation
The owning-side junction foreign key falls back to `relation.onDelete ?? "CASCADE"`, but the inverse side had no such fallback and used the inverse relation's onDelete/onUpdate directly. A bidirectional @manytomany without explicit options therefore generated an inverse foreign key with NO ACTION instead of CASCADE, so the two sides of the same join table disagreed. Apply the same CASCADE fallback to the inverse branches.
commit: |
Code Review by Qodo
1. Junction FK default undocumented
|
|
@kyungseopk1m Enable tests for other drivers as well and if possible move it functional tests. |
Relocate the typeorm#11738 regression test out of test/github-issues into the functional many-to-many suite and run it against all configured drivers instead of better-sqlite3 only. Assertions account for Spanner (no UPDATE/DELETE CASCADE) and Oracle (no UPDATE CASCADE), matching the junction builder's per-driver fallbacks.
|
@Cprakhar moved to the functional suite and enabled all drivers. assertions branch for spanner/oracle since those keep NO ACTION. |
…verse-relation-cascade-default
Description of change
Bidirectional many-to-many relations generate two junction foreign keys, and the default
onDelete/onUpdatewas inconsistent between them. The owning side falls back toCASCADEwhen no options are given, but the inverse side did not — it used the inverse relation'sonDelete/onUpdatedirectly, which isundefinedwhen the inverse@ManyToManydeclares no options, so it ended up asNO ACTION.For a plain bidirectional relation this means:
ON DELETE CASCADE ON UPDATE CASCADEON DELETE NO ACTION ON UPDATE NO ACTIONThis applies the same fallback used on the owning side to the inverse branches, so both foreign keys default to
CASCADE. Unidirectional relations are unaffected (they already went through theCASCADEbranch), and an inverse side with explicit options keeps its values.Verified with a new test under
test/github-issues/11738that builds the metadata for a bidirectional@ManyToManyand asserts both junction foreign keys useCASCADE. It fails on the current code (inverse FK isNO ACTION) and passes with the fix.tsc --noEmit, Prettier and ESLint are clean.Closes #11738
Pull-Request Checklist
masterbranchCloses #11738test/github-issues/11738/issue-11738.test.ts)CASCADEdefault