Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: relations: Orphaned row action #7105

Merged
merged 1 commit into from
Jan 12, 2021
Merged

Conversation

nebkat
Copy link
Contributor

@nebkat nebkat commented Nov 24, 2020

Rebase of #1665 with some modifications.


Per @adenhertog from the original PR:

This adds an additional option on one-to-many relationships where child entities are deleted, rather than having their foreign key set to null, when removed from their parent.

Many times we have the situation where a parent entity "owns" a child. An example of this is when a User has a set of RoleAssignment in the context of permissions. When a RoleAssignment is removed from the user, we expect for the row to be deleted. Previously the row would remain in the database but with the userId column set to null, leaving an orphaned row that would clog up the table.

This fix allows for RoleAssignment to specify on its relationship with User that it should be deleted, rather than orphaned, when the relationship is removed.

By default, the original behaviour of setting the foreign key to null is retained.


See also #6704, and other issues taken from it:

Closes #1761
Closes #2467
Closes #5645

Related #1286
Related #1351
Related #6382

Description of change

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run lint passes with this change
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change
  • The new commits follow conventions explained in CONTRIBUTING.md

Co-authored-by: adenhertog <andrew.denhertog@gmail.com>
@pleerock
Copy link
Member

Wow implementation was much simpler than I thought.
I guess we need to update documentation in another PR.
Thank you for contribution!

@ryanpagel
Copy link

Just used this feature, super useful. Thank you.

@jakubnavratil
Copy link

Does not trigger AfterRemove listener on removed entity.

@iamonkey
Copy link

Good feature, thanks for implementing!

zshipleyTAG pushed a commit to Amherst-Development/typeorm that referenced this pull request Oct 7, 2022
* typeorm-0.2.30: (212 commits)
  version bump
  docs: fix javascript usage examples (typeorm#7031)
  fix: resolve migration for UpdateDateColumn without ON UPDATE clause (typeorm#7057)
  fix: Error when sorting by an embedded entity while using join and skip/take (typeorm#7082)
  fix: resolves Postgres sequence identifier length error (typeorm#7115)
  feat: closure table custom naming (typeorm#7120)
  feat: relations: Orphaned row action (typeorm#7105)
  docs: fix invalid code block in "find many options" (typeorm#7268)
  docs: Embodying the example (typeorm#7116)
  docs: document withDeleted option (typeorm#7132)
  fix: return 'null' (instead of 'undefined') on lazy relations that have no results (typeorm#7146) (typeorm#7147)
  docs: update cascade options (typeorm#7140)
  docs: add .ts to supported ormconfig formats (typeorm#7139)
  fix: improve stack traces when using persist executor (typeorm#7218)
  refactor: remove Oracle multirow insert workaround (since typeorm#6927) (typeorm#7083)
  feat: add NOWAIT and SKIP LOCKED lock support for MySQL (typeorm#7236)
  docs: update OneToMany grammar (typeorm#7252)
  feat: JavaScript file migrations output (typeorm#7253)
  docs: update Repository.ts (typeorm#7254)
  chore: update dependency cli-highlight to v2.1.10 (typeorm#7265)
  ...
@adshrc
Copy link

adshrc commented Feb 23, 2024

but this is for OneToMany Relations only. ManyToMany does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants