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

Solving "have conflicting mods in update" when change Array order with new embedded objects

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

      When we need to change the order of one embedded Array, like the following code:

      person = Person.create
      existing_address = person.addresses.create(street: "Oxford St")
      new_address = person.addresses.build(street: "Oxford St")
      
      person.addresses[0] = new_address
      person.addresses[1] = existing_address
      

      So, when I call atomic_updates, Mongoid is not considering conflicts:

      {
        "$set" => {
          "title" => "Sir",
          "addresses.0.street" => "Bond St"
        },
        "$pushAll" => {
          "addresses" => [{
              "_id" => new_address.id,
              "street" => "Another",
              "locations" => [
                "_id" => location.id,
                "name" => "Home"
              ]
          }]
        }
      }
      

      The pull request consider $pullAll operation when Mongoid is generating $set operation.

      Other option to resolve the problem is change the method _children to return new embedded objects on the final of Array.

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

              Created:
              Updated:
              Resolved: