-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
I noticed a bug when updating after touching while investigating MONGOID-5291...
When performing calling #touch on a document and then subsequently updating the document, the updated_at is not updated on the second operation.
Here is a simple reproduce case:
Unable to find source-code formatter for language: ruby. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
class Band include Mongoid::Document include Mongoid::Timestamps field :name, type: String end Band.destroy_all Band.create! band = Band.first puts "BAND: #{band.updated_at}" # => BAND: 2022-09-29 18:59:01 -0400 sleep 2 band.touch puts "BAND: #{band.updated_at}" # => BAND: 2022-09-29 18:59:03 -0400 sleep 2 band.name = "Neil" band.save! puts "BAND: #{band.updated_at}" # => BAND: 2022-09-29 18:59:03 -0400 # WRONG this should have updated
The solution to this problem is to not mark the updated_at attribute changed on calling #touch, since it's already been persisted. This is consistent with Rails.
- has to be done after
-
MONGOID-5142 Perform a single write for all touches
- Closed
- is related to
-
MONGOID-5291 Clarify whether :touch option is applicable for all updates
- Closed