kibae / typeorm-auditing

TypeORM Auditing: Create history tables and manage changes of entity automatically.
https://www.npmjs.com/package/typeorm-auditing
MIT License
25 stars 3 forks source link

Does not work when using Query Builder #9

Open manvapatel-rbc opened 1 year ago

manvapatel-rbc commented 1 year ago

Hello again!, I noticed that the update does not work when using typeorm query builder (https://orkhan.gitbook.io/typeorm/docs/select-query-builder) I have a query like this:

await dataSource
    .createQueryBuilder()
    .update(User)
    .set({ firstName: "Timber", lastName: "Saw" })
    .where("id = :id", { id: 1 })
    .execute()

This does insert an update record in the audit table, but all the values are NULL.

Just wanted to know if this was a bug or if this is not supported.

Thank you!

kibae commented 1 year ago

Hello, @manvapatel-rbc Can you tell me if your Entity inherits from BaseEntity? And what database do you use? 🙏

kibae commented 1 year ago
image

I found the cause of this issue. This project uses TypeORM's subscriber feature. Looking at the code inside TypeORM's UpdateQueryBuilder.execute(), it doesn't pass the where condition when calling AfterUpdate subscriber. So, I don't think there is a way to fix this issue at this time. I'll submit a patch to TypeORM to fix this issue.

manvapatel-rbc commented 1 year ago

Ohh okay. Thanks for looking into it! So do you want me keep this issue open for the time being?

kibae commented 1 year ago

Yes, I'll leave it open until this issue is resolved. Please let me know if you have any other issues. Thank you.

klahdenk commented 11 months ago

Hi @kibae was there a patch submitted to typeorm regarding this one? Can't find it.