Make previous value available in @AfterUpdate function
See original GitHub issueBy popular request, it would be very useful if we could also access the previous state of objects being updated in @AfterUpdate functions
For example:
@Entity()
export class CartItem {
@AfterUpdate()
notifyCustomer() {
sendEmail(`An item in your cart has changed price from ??? to ${this.price}`
}
}
Could become
@Entity()
export class CartItem {
@AfterUpdate()
notifyCustomer() {
sendEmail(`An item in your cart has changed price from ${this.previous.price} to ${this.price}`
}
}
TypeORM already knows the previous value, as it will only call @AfterUpdate
if it detects a change, therefore, the feature would only require that to be exposed to developer.
Please see comment and thread - https://github.com/typeorm/typeorm/issues/1609#issuecomment-484303500
Thank you!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:39
- Comments:14
Top Results From Across the Web
Get OLD Value in MySQL Trigger AFTER Update Statement
In an UPDATE TRIGGER , you can use the OLD keyword to access the row data which is being replaced by the update....
Read more >Trigger.old and Trigger.new values before and after update ...
When a field value is changed to certain value, we use trigger.old and trigger.new to compare the older and new version values of...
Read more >Form.AfterUpdate event (Access) - Microsoft Learn
The AfterUpdate event is triggered when a control or record is updated. Within a record, changed data in each control is updated when...
Read more >Make previous value available in @AfterUpdate function
Make previous value available in @AfterUpdate function · Issue type: [ ] question · Database system/driver: Any · TypeORM version: Any · Steps...
Read more >Checking 'Correct' Previous value method in Trigger design ...
My method of choice when it comes to checking for field changes, is Dan Appleman's 'Correct' old Value method found in Chapter 6...
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 Free
Top 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
Is there a workarround for this @pleerock ?
I needed this, so I made some code to use this. It’s written in a subscriber, in my case to add timeline and audit trail logging.
This code will loop through the updatedColumns which we know from the event, and will lookup them in the databaseEntity and the events entity.
Maybe it will help someone
When using
EventSubscriber
you can hook toafterLoad
event and set the retrieved entity as a class property.