Skip to content

Conversation

@adenhertog
Copy link
Contributor

@adenhertog adenhertog commented Feb 27, 2018

Also, fix: #1351

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.

* Fix broken anchor link

* Update SqljsConnectionOptions.ts

* fix(docs): link to sqljs connection options

* Edit Replication  document

*  returns

* Update multiple-connections.md

* delete orphans implementation

* Determine subject removal in builder

* lint fixes
@pleerock
Copy link
Member

Im sorry but I cannot accept this PR.

First, persistence was completely refactored in @next, cascade removes are not working currently in next and Im not yet sure about their design and implementation.

If you want have this feature in @next then its better to start discussion before implementation since this area is very sensitive and must be implemented very carefully and right design should be chosen first.

@guscastro
Copy link
Contributor

I'd personally really like to have this feature in @next. Could we start the discussion with your concerns about the current implementation, @pleerock ?

guscastro and others added 2 commits March 6, 2018 14:32
…pplication from crashing out (#2)

* Handle pool/connection-level errors on different drivers to prevent application from crashing out

* Fix stupid stuff
* include tablepath when deleting rows

* revert gulp
@pleerock
Copy link
Member

pleerock commented Mar 9, 2018

@adenhertog I see you pushed some changes, but as I told if it will be implemented it must be re-implemented against next branch (and all changes it has)

@adenhertog
Copy link
Contributor Author

adenhertog commented Mar 13, 2018

Hey @pleerock, I'm happy to discuss how this might fit into @next as for certain situations it fits better than setting FKs to null. I'm currently using 0.1.13 with this patch in production since it was a bit urgent for me.

Can we discuss your concerns on this? if it's something that can be covered by some more tests then I can try to flesh out the scenarios you have in mind

@kirliam
Copy link
Contributor

kirliam commented Mar 14, 2018

Just for your information, this is a common use-case for me as well, and it would be nice if I could have the option to tell typeorm to delete the orphan entities, since today I am required to do it manually!

@kristophjunge
Copy link

Hello Guys,

please note that i have looked on this issue from a bug perspective in #1761 and also filed a pull request against @next.

Having cascade remove working in these cases is essential. Setting the foreign key to NULL only covers a portion of the possible situations.

If cascade remove is not working it basically renders all cascade methods to be unusable. I cannot implement "insert" and "update" one way and have some extra code to fill the missing "remove" part.

I can go only full with these features or completely without.

@adenhertog
Copy link
Contributor Author

Closing this since master has diverged by a major version. I'd still find it very useful having this addressed in the latest release

@adenhertog adenhertog closed this Aug 29, 2018
@haroldo-ok
Copy link

I am quite surprised that one of the top JS/TS ORM's does not support orphan removal...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove missing child objects in a relation

6 participants