Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
17
Help us understand the problem. What is going on with this article?

More than 5 years have passed since last update.

@Oakbow

update_allはlock_versionもupdated_atも更新しない

ActiveRecord の一括更新メソッドである update_all ですが、これを使うと lock_version や updated_at カラムを更新してくれません。

ActiveRecord::Relation#update_all does not update updated_at | github

これはこういう仕様のようです。やるなら自分でやれと。
仕方がないのでこんな風にやりました。

Task.where(:id.in => assign_tasks.map(&:id)).update_all(:status => 'entered')
        
Task.where(:id.in => assign_tasks.map(&:id))
.update_all(["status = 'entered', lock_version = lock_version + 1, updated_at = ? ", Time.now.utc])

実際に運用していると、こういう日付部分って障害や不具合が起きた時の調査の糸口になるので、できるだけちゃんと記録したくなるんですよね。

17
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
17
Help us understand the problem. What is going on with this article?