ExportXMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Unknown
    • 9.1.2, 9.0.13
    • Affects Version/s: 9.1.1, 9.0.12
    • Component/s: Autosave, Persistence
    • None
    • None
    • Fully Compatible
    • Ruby Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      A new (unsaved) `embeds_one` document under a persisted parent gets its `embeds_many` association assigned through `assign_attributes`. On save, Mongoid sends two `$set` keys, one for the whole embedded document and one for its child array, and the server rejects the update:

      Mongo::Error::OperationFailure: [40]: Updating the path 'group.items' would create a conflict at 'group'
      

      Assigning the same array with the plain setter (`group.items = [...]`) saves correctly.

      Failing case:

      Given:

      class Item
        include Mongoid::Document
        field :name, type: String
        embedded_in :group
      end
      
      class Group
        include Mongoid::Document
        field :matcher, type: String
        embedded_in :parent
        embeds_many :items
      end
      
      class Parent
        include Mongoid::Document
        embeds_one :group, autobuild: true
      end
      

      Then:
       

      parent = Parent.find(Parent.create!.id)
      parent.build_group(matcher: 'all')
      parent.group.assign_attributes(items: [{ name: 'a' }])
      parent.save!  # raises OperationFailure [40]
      

      Nested attributes into an autobuilt `embeds_one` fail the same way:

      parent.assign_attributes(group: { matcher: 'all', items: [{ name: 'a' }] })
      parent.save!  # raises OperationFailure [40]
      

        1. repro.rb
          2 kB
          Kieran Pilkington (EXT)

            Assignee:
            Jamis Buck
            Reporter:
            Kieran Pilkington (EXT)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: