update_attribute, update_attributes and update_column (Ruby on Rails)
update_attributes
tries to validate the record, calls callbacks and saves;update_attribute
doesn't validate the record, calls callbacks and saves;update_column
doesn't validate the record, doesn't call callbacks, doesn't call save method, though it does update record in the database.
总结:
update_attributes
一般最好都用这个,会有validate, callbacks, saves。 rails 回调会自动更新 updated_at ..等等
update_attribute 这个会跳过validate, 但是会有回调和save,
rails 回调会自动更新 updated_at
update_column update_columns 这个会跳过所有的步骤
validate, callbacks, save 直接运行sql 去update. 所以不会更新 updated_at, 像是偷偷的区更新了某个字段。
https://stackoverflow.com/questions/14415857/rails-update-column-works-but-not-update-attributes
https://maxivak.com/update_attribute-and-update_attributes-ruby-on-rails/