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

Embedded object ids change after deleting embedder object with paranoia

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.5
    • Affects Version/s: None
    • Component/s: None
    • None

      Hello,

      we have the following issue:

      class Cow
      
        include Mongoid::Document
        include Mongoid::Timestamps
        include Mongoid::Paranoia
      
        embeds_many :spots
      
      end
      
      class Spot
      
        include Mongoid::Document
        include Mongoid::Timestamps
      
        embedded_in :cow
      
      end
      
      cow = Cow.create
      cow.spots.push Spot.new
      
      Cow.first.spots
      [#<Spot _id: 51a78530b5b539772f000047, created_at: 2013-05-30 16:58:24 UTC, updated_at: 2013-05-30 16:58:24 UTC>]
      
      Cow.first.spots
      [#<Spot _id: 51a78530b5b539772f000047, created_at: 2013-05-30 16:58:24 UTC, updated_at: 2013-05-30 16:58:24 UTC>]
      

      Note, that the spot's id doesn't change, so it's working normally. Now let's delete the object with Paranoia:

      Cow.first.destroy
      
      Cow.deleted.first.spots
      [#<Spot _id: 51a78564b5b539772f000048, created_at: 2013-05-30 16:58:24 UTC, updated_at: 2013-05-30 16:58:24 UTC>]
      
      Cow.deleted.first.spots
      [#<Spot _id: 51a78565b5b539772f000049, created_at: 2013-05-30 16:58:24 UTC, updated_at: 2013-05-30 16:58:24 UTC>]
      

      As you can see, the spot's id changes every time when it gets loaded. After cow is restored, the spot gets a totally new id again, but it remains the same after every load from then:

      Cow.deleted.first.restore
      
      Cow.first.spots
      [#<Spot _id: 51a78850b5b5392898000002, created_at: 2013-05-30 17:11:44 UTC, updated_at: 2013-05-30 17:11:44 UTC>]
      
      Cow.first.spots
      [#<Spot _id: 51a78850b5b5392898000002, created_at: 2013-05-30 17:11:44 UTC, updated_at: 2013-05-30 17:11:44 UTC>]
      

      The problem is present in 3.1.2 - 3.1.4 versions. Could you please take a look at it? Thanks in advance!

            Assignee:
            arthurnn Arthur Nogueira Neves
            Reporter:
            whatwho whatwho
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: