-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
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.