Header_image
Jeremy Walker

Software Developer & Social Entrepreneur

Rails' update_attribute is deprecated from 3.2.7

The difference between update_attribute and update_attributes has confused new Rails developers for a long time. The key difference was that update_attribute did not run validations, where as update_attributes did.

As of Rails 3.2.7, update_attribute no longer exists in master and is deprecated in Rails 3. Xavier Noria provided a bit of history on this in a Rails Core group thread on the issue, which I found interesting.

So, to summarise:

  • If you use update_attribute provided, change to update_column.
  • If you use update_attributes, you can carry on as normal.

Share This Post

Comments

11c3ac04d669661020cf80a822cd9620

Robert Reiz

Good to know. I am using "update_attributes" in VersionEye. What is the equivalent for that? "update_columns"? Or should I use "update_column" multiple times for each column? That would be not so cool.

955103d80e386882143a78875fb727bf

Jeremy Walker

Robert - update_attributes will stay as it is. It's only update_attribute that's been removed :)

993fccf1b3cc1470d2e84b2e25737a15

Grammar Nazi

Deprecated. Deprecated. Deprecated.

Ce7969be593ab900bd4ab4e1f2c27d08

scarver2

Not sure yet why update_attribute is deprecated. update_column does not perform callbacks including updating the timestamp as update_attribute does. Does anyone have a recommendation for a one-liner, fast executing code to accomplish the same functionality?

92db31ff036a0b365b88536674cb9352

TC

Hi,

So, one replaces one confusing method with another one? ActiveRecord should abstract the connection between physical and logical representation, in my eyes. Therefore, the notion or exposal of column confuses me in an ActiveRecord model. Not to mention, both functions behave differently. update_attribute could be called on a new record, update_column can't.

Not defending update_attribute here, just suggesting the solution might not have been the perfect one, at least in my opinion.

Post a Comment

I'd love to hear your thoughts :)