question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Repository Remove method deletes the Entity Id

See original GitHub issue

Issue 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

typeOrm-issue

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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
br0wncommented, Nov 23, 2020

@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.

2reactions
nebkatcommented, Nov 23, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found