Using ActiveRecord, is there a way to get the old values of a record during after_update

后端 未结 10 1044
耶瑟儿~
耶瑟儿~ 2021-01-30 08:20

Setup using a simple example: I\'ve got 1 table (Totals) that holds the sum of the amount column of each record in a second table (

10条回答
  •  北海茫月
    2021-01-30 08:48

    Firstly, you should be doing this in a transaction to ensure that your data gets written together.

    To answer your question, you could just set a member variable to the old value in the before_update, which you can then access in the after_update, however this isn't a very elegant solution.

提交回复
热议问题