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

update double embedded = attribute with blank key

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 6.1.1
    • Affects Version/s: None
    • Component/s: None
    • None

      Strange one. Here's a simple test case:

      class Library
        include Mongoid::Document
        embeds_one :book
      end
      class Book
        include Mongoid::Document
        embedded_in :library
        embeds_many :pages
      end
      class Page
        include Mongoid::Document
        embedded_in :book
        field :text
      end
      
      l = Library.create!
      l = Library.find(l.id)
      l.attributes = { book: { pages: [ text: "hello, world" ] } }
      l.save
      
      p Library.first
      

      It prints this:

      #<Library
        _id: xxx,
        : {"_id"=>"xxx", "pages"=>[{"_id"=>"xxx", "text"=>"hello, world"}]},
        pages: [{"_id"=>"xxx", "text"=>"hello, world"}]>
      

      Notice that the book field ended up with a blank key, and somehow the pages were $set in the parent. Yikes. I suspect this is some kind of initialization race when calculating atomic paths.

      Also note that it only occurs when updating documents. If you use Library.new instead of create!/find, the document is setup correctly.

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            gurgeous Adam Doppelt
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: