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

Unexpected update behavior on embeds_many after pull MONGOID-966

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

      1df72de apparently fixed MONGOID-964 but after going through and narrowing down this behavior commit by commit, I have found that the following is caused by 1df72de:

      # Product embeds many Variations.
      # this is a totally empty rails 3 ruby 1.9.2 project specifically for testing mongoid
      
      # setup a product
      > p = Product.create
       => #<Product _id: 4e2c05a32abea95226000001, _type: nil, tag_ids: []> 
      >  p.variations.create
       => #<Variation _id: 4e2c05a52abea95226000002, _type: nil, name: nil> 
      
      # get the product
      > p = Product.last
       => #<Product _id: 4e2c05a32abea95226000001, _type: nil, tag_ids: []> 
      > a = p.attributes
       => {"_id"=>BSON::ObjectId('4e2c05a32abea95226000001'), "tag_ids"=>[], "variations"=>[{"_id"=>BSON::ObjectId('4e2c05a52abea95226000002')}]} 
      > p = Product.last
       => #<Product _id: 4e2c05a32abea95226000001, _type: nil, tag_ids: []> 
      
      # update it with its own attributes
      > p.update_attributes(a)
       => true 
      
      # the embedded document has been duplicated and even has the same ID.
      > Product.last.variations
       => [#<Variation _id: 4e2c05a52abea95226000002, _type: nil, name: nil>, #<Variation _id: 4e2c05a52abea95226000002, _type: nil, name: nil>] 
      

      This only happens after 1df72de.

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

              Created:
              Updated:
              Resolved: