26
20

More than 5 years have passed since last update.

rails4でupdated_atを更新せずにupdateする -> update_columnを使う

Posted at

あんまり使いませんが、updated_atを更新せずcallbackやvalidationを行わないで特定カラムをただただ上書きしたい時に使います。

ここに書いてある通りの内容です。

image = Image.first
puts image.updated_at # updated_atが

image.update_column(:optimized, true)
puts image.updated_at # 更新されていない

image.update_attribute(:optimized, true)
puts image.updated_at # 更新されている

管理画面でupdated_atをソート表示に利用しているような時、updated_atが更新されたら困るケース等で使えます。

26
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
20