-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Unable to delete subordinate relation entity when saving parent entity #3938
Comments
Can you provide your entity definitions? Without them we have to guess how exactly they're defined and which statement should be used. |
I'm facing a similar issue when updating the instances on the Many side of a One to Many relation. When setting The relevant part of my code is:
Then running Is there a way to make typeorm delete the old Thanks |
I think you're looking for this: #1460 |
@amiiit I'm having the same issue, what did you do to fix this. I have tried onUpdate: 'CASCADE' but it still adds null to the old many's and doesn't delete them? |
i'm also having the same issue, and adding onUpdate: 'CASCADE' does not work |
I have the same issue. I did "solve" it by deleting the property instead of assigning an empty array. The problem persists if you remove one of many elements and the array is not empty. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Any advice on this issue @pleerock? I know it's always been this way (ie typeorm will not handle it) but maybe just updating this issue with that direction would help. Then we know it's not something we've misconfigured. We have to manage it ourselves. |
Hi @greenreign |
For anyone still looking for a fix, here is a patch to correct this. Use it with patch-package. https://gist.github.com/yleflour/0bda286aef0b80c16000ae7c93107178 I don't think I will be opening an official PR with this change as it would be an undocumented cascading effect. A proper solution should require its own configuration parameter in the OneToMany relationship decorator |
Hi @yleflour , Thanks for you sugestion. I tried to implement it, but i get the same error. Can you help me? |
@shindiogo My check uses the I believe that adding the option |
This comment has been minimized.
This comment has been minimized.
I used orphanedRowAction and it worked for me. Parent:
Child:
|
Thanks @douglasgsouza, your suggestion works well! Here's the doc for anyone interested. As far as I can tell, this solves it and the issue and can be closed? |
Works here! Thanks, i think this can be closed. |
Closing as it seems this has been resolved. |
Still working, thanks mate ! |
Thanks that was the solution for my problem ! |
Issue type:
[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]
mongodb
[ ]
mssql
[x]
mysql
/mariadb
[ ]
oracle
[ ]
postgres
[ ]
cockroachdb
[ ]
sqlite
[ ]
sqljs
[ ]
react-native
[ ]
expo
TypeORM version:
[x ]
latest
[ ]
@next
[ ]
0.x.x
(or put your version here)Steps to reproduce or a small repository showing the problem:
My intention was to remove the subordinate entities in a relation from the parent entity.
For example, I've a
Photo
entity which has a one-to-many relation setup with another entityMetaData
. So, when I retreive aPhoto
entity withMetaData
relation, thePhoto
entity should have a shape like this:Basically, the
metaDatas
property inPhoto
entity will be an array. My intention is to remove allMetaData
from thePhoto
entity.What I did was simply by setting the array of
photoEntity.metaDatas
to an empty array and then savephotoEntity
like so:However, this throws an error that
Column 'photoId' cannot be null
. This is because instead of running aDELETE
query, the SQL TypeORM did anUPDATE
this:sql: 'UPDATE `metaData` SET `photoId` = NULL, `updatedAt` = CURRENT_TIMESTAMP WHERE `metaDataId` = `123` }
Shouldn't a
DELETE
query be run instead of an update one?In this case, how can I remove the
MetaData
entities from thePhoto
entity?The text was updated successfully, but these errors were encountered: