How to Increament a row value before update


Hellos I am just wondering if their is away I can use to increment a row value using current row value before updating i.e

 this.addHook('beforeSave', async (modelInstance) => {
        let increament_val = (current_row_value)
        if (modelInstance.dirty.paid) {
            modelInstance.paid = modelInstance.paid + increament_val



What’s the issue with the code you are running. Also you want to increment to every update?


Thanks for replying, no issues with the code, I just want to know how I can increment an entry value before update. Yes all updates



Hi @fredrickreuben

You can probably learn more about Lifecycle Events here

You can actually use beforeUpdate and afterUpdate in your models.