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

Allow _ids to be modified in embedded documents

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 8.1.0, 9.0.0
    • Affects Version/s: None
    • Component/s: None
    • None

      It should be possible to change _ids on embedded documents. The following code does not work: 

      class Kangaroo
        include Mongoid::Document
        embeds_one :baby
      end
      
      class Baby
        include Mongoid::Document
        embedded_in :kangaroo
        
        field :name, type: String
      end
      
      kangaroo = Kangaroo.new
      baby = Baby.new(name: 'test1')
      kangaroo.baby = baby
      kangaroo.save!
      kangaroo.update(baby: { _id: BSON::ObjectId.new, name: 'test2'}) 

      When updating an embedded document with a new _id, the entire update is ignored (quietly, but MONGOID-5225 is trying to fix that). 

       

      This ticket proposes that we allow for the _id to be updated in embedded documents 

            Assignee:
            jamis.buck@mongodb.com Jamis Buck
            Reporter:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: