如何确定模型/嵌套模型中的任何字段是否已更改? [英] How to determine if any field in a model / nested model changed?
本文介绍了如何确定模型/嵌套模型中的任何字段是否已更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一些快速的方法可以找出模型的任何字段或其嵌套模型的任何字段(也称为关联)是否发生更改?
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?
推荐答案
要查看 ActiveRecord 对象是否发生变化,可以调用:
To see if a ActiveRecord object has changed, you can call:
instance.changed?
要查看特定属性是否已更改,您可以执行以下操作:
To see if a specific attribute was changed, you can do:
instance.attr_changed?
其中 attr 是您要检查的属性.
where attr is the attribute you want to check.
要检查嵌套模型是否已更改,您只需执行以下操作:
To check for if a nested model changed, you can just do:
instance.nested_model.changed?
这篇关于如何确定模型/嵌套模型中的任何字段是否已更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文