如何确定是否在模型/嵌套模型中的任何领域的改变? [英] How to determine if any field in a model / nested model changed?

查看:130
本文介绍了如何确定是否在模型/嵌套模型中的任何领域的改变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一些快速的方法来找出是否有任何模型的领域或它的任何领域的嵌套模型(又名协会)变化?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆