开发者

Is there any method available to find changed attributes for objects?

I want to fetch only changed attributes of an object. Is there any method available which returns all the updated at开发者_如何学Pythontributes?


Given there aren't many specifics in your question, I'm going to assume you're referring to ActiveRecord objects. To view the changed attributes on so called "Dirty Objects" you can do the following:

User.changed #=> ["name", "email"]

User.changes #=> { "name" => ["Joe", "Joseph"] }

There are also methods for each attribute if you need to check specific ones.

User.name_changed? #=> true

User.name_change #=> ["Joe", "Joseph"]

More details here: http://ryandaigle.com/articles/2008/3/31/what-s-new-in-edge-rails-dirty-objects


Yes ActiveRecord:Dirty, however you can't see changes to objects saved to the Db, such as user.save :(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜