Proposal: add `touch` option for update_columns/update_column

Hey there! I find a problem that Persistence#update_colums and Persistence#update_colum do not update timestamps. Those methods are often used for performance reasons or to skip callbacks/validations, but it’s a common mistake to forget to provide updated timestamps. Also, there are no options, other than to provide updated_at/updated_on (or some other timestamp) explicitly. So there are a couple of proposals:

  1. What do you think about providing a touch option similar to what Rails have for Persistence#increment!
  2. Also it will be awesome to change the update_colums/update_colum behavior to respect model’s record_timestamps configuration as it works ie for Persistence#save, Persistence#update, etc. Of course, it may be unexpected, because skipping timestamps update defaulted since introducing those methods and might be configurable. For example config.update_columns_respects_record_timestamps = true.

Ideally, it would be nice to have both options, but any of them would be already better than the current situation. Let me know what you think about it!

I’ve been working on this problem for a while, so I will happily open a PR, as soon as it is ready and the team confirms it is a good idea. Thanks!

I’ve opened a PR to implement the p1 of this proposal Add `touch` option to `#update_columns` and `#update_column` methods by moofkit · Pull Request #51455 · rails/rails · GitHub

1 Like