-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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: orphanedRowAction=disabled (rebase of PR 8285) #8678
Feat: orphanedRowAction=disabled (rebase of PR 8285) #8678
Conversation
docs/relations.md
Outdated
@@ -25,7 +25,8 @@ There are several options you can specify for relations: | |||
* `onDelete: "RESTRICT"|"CASCADE"|"SET NULL"` - specifies how foreign key should behave when referenced object is deleted | |||
* `primary: boolean` - Indicates whether this relation's column will be a primary column or not. | |||
* `nullable: boolean` - Indicates whether this relation's column is nullable or not. By default it is nullable. | |||
* `orphanedRowAction: "nullify" | "delete" | "soft-delete"` - When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted (delete or soft delete). | |||
* `orphanedRowAction: "nullify" | "delete" | "soft-delete" | disable` - When a parent is saved (cascading enabled) without a child/children that still exists in database, this will control what shall happen to them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take new option into quotes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disable
must be "disable"
Tests are failing.... |
@pleerock postgres test fails because of unexpected data, but this must be a quirk within relation update mechanism. Shortened info on what is happening: const userToUpdate = (await userRepo.findOne(userId))!;
userToUpdate.settings = [
userToUpdate.settings[0],
// create modified version of setting at index 1
{ ...userToUpdate.settings[1], data:"bar_updated" },
];
await userRepo.save(userToUpdate); then the user is fetched again and its settings entries are checked. |
@jbjhjm not sure I understand the problem |
Postgres test fails because it didn't persist changes on related item correctly. |
Also it looks weird that test is only failing for postgres version 12 |
Simplify test suite to comply with postgres12
@jbjhjm did you upgrade to 0.3.0 ? Maybe we can make it 0.3.0 feature? I'm going to stop accepting PRs for 0.2.x very soon and release 0.3.0 |
Oh, I was not aware of 0.3.0 @pleerock ! Let's continue with 0.2.x but I'll also open a mirrored PR for the 0.3.0 branch, ok? |
I've been digging into some issues related to unwanted nullified references for quiet some hours until I came across this issue :D just for reference, I'm adding another use-case for this PR (thank you @jbjhjm in the meantime for your effort you've put into this PR). We have soft-deletion in place (a custom one due to how other applications handled it in the past) and when updating one-to-many relations and not passing some soft-deleted children, it tries to set it's reference to null, even if it should just ignore it. So looking really forward to this pull request :) |
@jbjhjm sorry to annoy you again, but I would like to ask you to rebase it against latest master, since latest master is 0.3.0 already, and I don't have plans to accept new PRs into 0.2.0 |
@pleerock will do but it'll take some time, haven't even touched 0.3.x yet due to the breaking changes and tight time. |
@jbjhjm np |
…ion-none-rebase # Conflicts: # docs/relations.md # src/decorator/options/RelationOptions.ts # src/entity-schema/EntitySchemaRelationOptions.ts # src/metadata/RelationMetadata.ts # src/persistence/subject-builder/OneToManySubjectBuilder.ts # test/functional/persistence/delete-orphans/entity/Category.ts # test/functional/persistence/delete-orphans/entity/Post.ts # test/functional/persistence/orphanage/delete/delete-orphans.ts
@pleerock alright, I ported it to current master. I was not able to run any local tests, getting a Jscript error popup stating typeorm cli.js contains an error. No idea. Are tests currently run on CircleCI? I see only lint + build checks here. |
you need to run prettier to fix lint issues. Also please merge latest master into your branch again because it contains few important fixes on tests are running in CI. |
…ned-row-action-none-rebase
fixed, looks good @pleerock |
@pleerock @AlexMesser please check. I did half a dozen rebases for this due to waiting time and I really don't want to do it another time. |
thanks you for all your efforts and patience @jbjhjm |
@jbjhjm sorry to bother you, I'm having trouble understanding this option you added. I have a parent & child entity (renamed to "Document" and "Page" for this example). I want to ensure the following:
|
Hi @nrathi , I think orphanedRowAction is not what you are looking for. To prevent deletion of a Document that still has Pages assigned, take a look at the "onDelete" option. Also take a look at this: #8277 About the Good luck! |
@pleerock
This is a new PR based on orphanedRowAction=skip PR #8285
Fixes #8275
Implementation is as before, just rebased to include commits added in the meantime.
Also, instead of keyword "skip" it is now using "disabled", as discussed in other PR.