开发者

Why is ActiveRecord::Base#update_attributes deprecated?

开发者 https://www.devze.com 2023-02-28 17:07 出处:网络
I noticed in the Rails docs here that the update_attributes method is deprecated: This method is deprecated on the latest stable version of Rails. The last existing version (v2.3.8) is shown here.

I noticed in the Rails docs here that the update_attributes method is deprecated:

This method is deprecated on the latest stable version of Rails. The last existing version (v2.3.8) is shown here.

I'm curious to know why it was deprecated and what is preferred in its place.

It isn't a matter of enormous consequence for me right now as the method 开发者_开发技巧works fine in my Rails 2.x apps. However, in anticipation of upgrading to Rails 3 some day I'd like to start getting a grasp on what I'll need to change and how things are done differently.


Apidock is a little misleading, it actually says "deprecated or moved"; the latter is true, the former is not. ActiveRecord::Base includes ActiveRecord::Persistence, which defines #update_attributes. You can view the docs for this on apidock at http://apidock.com/rails/ActiveRecord/Persistence/update_attributes.

While this is also in ActiveResource now, there's no shared implementation of update_attributes, and you shouldn't look there for ActiveRecord::Base-related documentation, or vice versa.


In Rails 6 it became really deprecated. The reasons was discussed here:

https://github.com/rails/rails/pull/31998

The explanation is that both update_attributes and update_attributes! are just alias for update and update! for years and they can sound confusing (because of their singular versions: update_attribute).

0

精彩评论

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