Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2291

#touch sometimes updates more than just the timestamp

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      From MONGOID-2195, I learned that saving an embedded document directly will not #touch the parent, even if that parent includes Mongoid::Timestamps. I therefore write an #after_save callback on the embedded document to #touch the parent.

      Recently, I discovered that Mongoid sometimes sets more than just the updated_at attribute when #touch is called. The failing spec in this pull request illustrates the issue.

      In the spec, I add a second location to an address on a person. The queries run on MongoDB are:

      update flags:0 q:

      { _id: ObjectId('502bdae523e2f62e68000001'), addresses._id: "hobrecht" }

      o:{ $pushAll: { addresses.0.locations: [

      { _id: ObjectId('502bdae523e2f62e68000003'), name: "home" }

      ] } }

      and then for #touch:

      update flags:0 q:

      { _id: ObjectId('502bdae523e2f62e68000001') }

      o:{ $set:

      { updated_at: new Date(1345051365963) }

      , $pushAll: { addresses.0.locations: [

      { _id: ObjectId('502bdae523e2f62e68000003'), name: "home" }

      ] } }

      As you can see, there is a $pushAll in the second query that sets updated_at.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jpmckinney jpmckinney
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: