Repository Remove method deletes the Entity Id
See original GitHub issueIssue Description
I have a simple delete function
async delete(id: number) {
const entity = await this.findOne(id);
console.log(`Entity Before: `, entity);
const res = await this.repo.remove(entity);
console.log(`Delete Result: `, res);
console.log(`Entity After: `, entity);
return res;
}
After remove the i do not get the id in the response and it is also removed from the entity as well
Expected Behavior
Id should not be removed
Actual Behavior
My Environment
Using in NestJs
| Operating System | ElementryOs | | Node.js version | v12.18.4 |
| TypeORM version | 0.2.29 |
Relevant Database Driver(s)
-
postgres
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Should a repository delete/remove an entity by passing in an ...
I am currently creating a repository and was wondering ...
Read more >Spring Data JPA Delete and Relationships - Baeldung
Explore different ways to delete entities in Spring Data JPA. ... Among others, CrudRepository contains two methods: deleteById and ...
Read more >Spring Data JPA Tutorial - #19 - deleteById() Method - YouTube
Hi, welcome to the Spring Data JPA tutorial series/course.In this lecture, we will learn how to delete an entity by id using the ......
Read more >Deleting JPA Entity Objects - ObjectDB
In order to delete an object from the database it has to first be retrieved (no matter which way) and then in an...
Read more >How do I delete entity object in JPA? - Kode Java
The first class that we are going to create is ArtistDaoImpl which implements ArtistDao . This DAO class handles the delete process either...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nebkat @all2pie I also stumbled upon this issue, as I like to return the removed/deleted entity(s) as a result of “delete” action…
Here is the code that is handling this case: https://github.com/typeorm/typeorm/blob/70938017ff17dc21e4a98512479b3645a78665e5/src/persistence/SubjectExecutor.ts#L681
I would like to understand what was the reason for implementing it like this.
Well spotted @br0wn, this was added in aa5670a04554cfcbf6f89ccb21016ec4948bc65f, not much info there.
I presume the logic was to ensure that the entities would no longer be used elsewhere or conflict with newly inserted items? If the items are to be re-added it should be with new IDs probably.