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

assign_attributes to embedded child & deleting in the same association which itself is embedded produces bogus results

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 7.3.3
    • Component/s: Persistence
    • None

      Hello

      We are having an issue with the following:

      Data model: House embeds_many Rooms which embeds_many Residents
      Actions -

      1. using assign_attributes to modify the last resident name
      2. deleting any resident other than the last resident
      3. saving

       

      Expected outcome: 

      1. The residents array size should be reduced by 1
      2. the last resident name to be modified correctly

      Actual outcome:

      The residents array size stays the same

      1. The before last resident element should be the last element, and its name is not modified as expected
      2. The last resident element is new "zombie" without an _id
      3.  The last resident element zombie has the name that is supposed to be in the before last element 

       

      Attached a gist to reproduce the issue. following is an example of the House record after the run:

      /* 1 */
      {
          "_id" : ObjectId("628e8ade8d8b192100b504d1"),
          "rooms" : [ 
              {
                  "_id" : ObjectId("628e8ade8d8b192100b504cc"),
                  "residents" : [ 
                      {
                          "_id" : ObjectId("628e8ade8d8b192100b504d2"),
                          "name" : "dude no 0"
                      }
                  ]
              }, 
              {
                  "_id" : ObjectId("628e8ade8d8b192100b504cd"),
                  "residents" : [ 
                      {
                          "_id" : ObjectId("628e8ade8d8b192100b504d3"),
                          "name" : "dude no 1"
                      }
                  ]
              }, 
              {
                  "_id" : ObjectId("628e8ade8d8b192100b504cf"),
                  "residents" : [ 
                      {
                          "_id" : ObjectId("628e8ade8d8b192100b504d5"),
                          "name" : "dude no 3"
                      }
                  ]
              }, 
              {
                  "_id" : ObjectId("628e8ade8d8b192100b504d0"),
                  "residents" : [ 
                      {
                          "_id" : ObjectId("628e8ade8d8b192100b504d6"),
                          "name" : "dude no 4"
                      }
                  ]
              }, 
              {
                  "residents" : [ 
                      {
                          "_id" : ObjectId("628e8ade8d8b192100b504d7"),
                          "name" : "the new dude"
                      }
                  ]
              }
          ]
      } 

       

      Not sure if the cause if improper use of `assign_attributes` (or something else wrong with the gist...). 

      Please advise

      Thank you
      Boaz

       

      p.s.

      Love the T-Shirt Size input 

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            boaz@honeybook.com Boaz Adato
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: