Skip to content
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

softRemove DeleteDateColumn is null at Susbscriber's AfterUpdate method #6327

Closed
aykutcan opened this issue Jun 29, 2020 · 9 comments · Fixed by #8318
Closed

softRemove DeleteDateColumn is null at Susbscriber's AfterUpdate method #6327

aykutcan opened this issue Jun 29, 2020 · 9 comments · Fixed by #8318

Comments

@aykutcan
Copy link

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)

Problem

softRemove() method triggers afterUpdate() without specified @DeleteDateColumn

I cant access deleted_at column to detect deletion of that entity and remove it from elasticsearch

Steps to reproduce or a small repository showing the problem:

Create User Entity with DeleteDateColumn decorator

@Entity({ name: 'users' })
export class User {

...

    @Index('users.deleted_at')
    @DeleteDateColumn({ name: 'deleted_at' })
    deleted_at: Date;

...

}

Create UserSubscriber

@EventSubscriber()
export class UserSubscriber implements EntitySubscriberInterface<User> {
    listenTo() {
        return User;
    }

    afterUpdate(event: UpdateEvent<User>): any {
        console.log(`AFTER UPDATE: `, event.entity);
    }

}

Trigger softRemove on an entity

    let user = await userRepository.findOne(5);
    await userRepository.softRemove(user);

What it should do

Return removed entity with deleted_at column filled

What it does

Return entity with null deleted_at column

@cantoute
Copy link

+1: same with sqlite

@lucasbemol
Copy link

+1: same with postgresql

@spotykatch
Copy link
Contributor

spotykatch commented Sep 2, 2021

So, we've got a bug here, I guess, but that still does not solve the problem. The function should return isDeleteDate or there should be a function for softRemove.

return column.isUpdateDate || column.isVersion;

For some reason, this returns undefined.
const loadedReturningColumns = await this.queryRunner.manager

Oh, yea. Query builder should use .withDeleted().

@spotykatch
Copy link
Contributor

spotykatch commented Sep 10, 2021

And the last one.

if (this.updateSubjects.length)

Must be

// update soft-removed entity properties
if (this.softRemoveSubjects.length)
    this.updateSpecialColumnsInInsertedAndUpdatedEntities(this.softRemoveSubjects);

// update recovered entity properties
if (this.recoverSubjects.length)
    this.updateSpecialColumnsInInsertedAndUpdatedEntities(this.recoverSubjects);

@sofia-cloudman
Copy link

+1 here

@zeek89
Copy link

zeek89 commented Oct 12, 2021

hi there, any chances this will be fixed any time soon?

@alls23
Copy link

alls23 commented Oct 12, 2021

I need a lot this fix

@spotykatch
Copy link
Contributor

spotykatch commented Oct 13, 2021

The pr is been sent. But I don't have much experience with it. First CircleCI builds for cockroach failed due to timeout. Merge with the new version of typeorm passed the tests. But merge doesn't seem to be included in the pr. If you can help me with it, I would be very grateful.
PR: #8227

@zeek89
Copy link

zeek89 commented Oct 19, 2021

hi spotykatch, first of all thanks for your work!
I am afraid we can do nothing but wait until someone merges the PR.

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