typeorm-auditing
typeorm-auditing copied to clipboard
Does not populate foreign key
Hello, Thanks a lot for developing this...it is really helpful!
I noticed that the library does not populate the foreign key field.
I have a relation like this:
@ManyToOne(
() => UserEntity,
user => user.waitlist,
)
@JoinColumn({ name: 'member_id' })
@ApiProperty({ type: () => UserEntity })
public user: UserEntity;
The member_id field is populated in the main entity but not in the audit entity.
Is this not supported? Do I need to use @BeforeInsert for this?
Hello, @manvapatel-rbc This was not intended behavior. It's a bug, so I fixed it and released version 0.5.5 to npm. Thanks for reporting the problem. Please let me know if there are any other problems. 🙏
Thank you! But I just tested out the new version and now I am getting this error
Error: DataSource is not set for this entity.
at Function.getRepository (/Users/manvapatel/Desktop/be/node_modules/typeorm-auditing/src/repository/BaseEntity.ts:115:19)
at Function.create (/Users/manvapatel/Desktop/be/node_modules/typeorm-auditing/src/repository/BaseEntity.ts:189:21)
at AuditingSubscriber.<anonymous> (/Users/manvapatel/Desktop/be/node_modules/typeorm-auditing/dist/auditing-subscriber.js:36:43)
at Generator.next (<anonymous>)
at /Users/manvapatel/Desktop/be/node_modules/typeorm-auditing/dist/auditing-subscriber.js:14:71
at new Promise (<anonymous>)
at __awaiter (/Users/manvapatel/Desktop/be/node_modules/typeorm-auditing/dist/auditing-subscriber.js:10:12)
at AuditingSubscriber.saveHistory (/Users/manvapatel/Desktop/be/node_modules/typeorm-auditing/dist/auditing-subscriber.js:29:16)
at AuditingSubscriber.<anonymous> (/Users/manvapatel/Desktop/be/node_modules/typeorm-auditing/dist/auditing-subscriber.js:46:25)
at Generator.next (<anonymous>)
at /Users/manvapatel/Desktop/be/node_modules/typeorm-auditing/dist/auditing-subscriber.js:14:71
at new Promise (<anonymous>)
at __awaiter (/Users/manvapatel/Desktop/be/node_modules/typeorm-auditing/dist/auditing-subscriber.js:10:12)
at AuditingSubscriber.afterInsert (/Users/manvapatel/Desktop/be/node_modules/typeorm-auditing/dist/auditing-subscriber.js:45:16)
at /Users/manvapatel/Desktop/be/src/subscriber/Broadcaster.ts:169:56
at Array.forEach (<anonymous>)
I have setup the data source properly and it works with the previous version.
@manvapatel-rbc I published 0.5.6 version to npm. Can you check this?
If the problem persists, can you show me the entity definition and the code that caused the above error? 🙏
@kibae Yes that worked! Thank you! Another thing I noticed was that it populated the foreign key properly on creation. But when I update the record, the new entry does not populate the foreign key. Which is fine for me...but I just wanted to bring that to your attention
@manvapatel-rbc I think it's a bug. I'll try to find out where the problem is. Thank you. 🙏
Hi pals. Any progress here?
Hello, @lzkill @manvapatel-rbc
I checked through this test case and there was no problem when updating using BaseEntity and repository. Could you please show me the code where the problem occurs?
https://github.com/kibae/typeorm-auditing/commit/5e7b0829234354a3edf39b7dd215297a49cc1e72#diff-f62b2ebb388631b83b005b34aae44882d389aba552035ac581ec8e1559923b85R60
Hi @kibae @lzkill I checked again and it seems to be working fine. I can't reproduce the issue I was having earlier