How to determine if any field in a model / nested model changed?

后端 未结 4 1918
执笔经年
执笔经年 2020-12-25 10:45

Is there some quick way to find out if any of a model\'s fields or any fields of it\'s nested models (a.k.a. associations) changed?

4条回答
  •  伪装坚强ぢ
    2020-12-25 11:10

    You can determine if an object has changed but not yet been saved by calling:

    my_object.changed?
    

    You can also determine if individual attributes have changed (say you have a first_name attribute):

    my_object.first_name_changed?
    

    As far as nested models go, I think you'd have to call changed? on them each individually.

提交回复
热议问题