-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Unknown
-
Affects Version/s: 9.1.0
-
Component/s: None
-
None
-
None
-
Fully Compatible
-
Ruby Drivers
-
Not Needed
-
None
-
None
-
None
-
None
-
None
-
None
Likely due to MONGOID-5867 - the save of a new embeds_one document uses $set and this now gets overwritten by the parent touch $set.
Reproduction:
require 'mongoid' Mongoid.configure do |c| c.clients.default = { hosts: ['localhost:27017'], database: 'mongoid_embed_repro' } end puts "Mongoid version: #{Mongoid::VERSION}" class Parent include Mongoid::Document include Mongoid::Timestamps embeds_one :child end class Child include Mongoid::Document field :label, type: String embedded_in :parent end Parent.delete_all parent = Parent.create! # persisted, has updated_at + created_at child = parent.create_child(label: "c1") # bug: embedded_in defaults to touch: true puts "" puts "ruby-side: child.persisted? = #{child.persisted?}" puts "ruby-side: parent.child = #{parent.child.inspect[0,80]}" raw = Parent.collection.find(_id: parent.id).first puts "db-side: raw keys = #{raw.keys.inspect}" puts "db-side: raw['child'] = #{raw['child'].inspect}" parent.reload puts "post-reload: parent.child = #{parent.child.inspect[0,80]}" # Expected: # raw['child'] => the embedded doc as BSON # parent.reload.child => Child instance # Actual on mongoid master 9.1.0: # raw['child'] => nil # parent.reload.child => nil # child.persisted? => true (still - silent failure)
Output:
Mongoid version: 9.1.0 ruby-side: child.persisted? = true ruby-side: parent.child = #<Child _id: 6a02a19c96570055c2a06135, label: "c1"> db-side: raw keys = ["_id", "updated_at", "created_at"] db-side: raw['child'] = nil post-reload: parent.child = nil
- is duplicated by
-
MONGOID-5946 REGRESSION: `embeds_one` reassignment on a persisted parent is dropped (Mongoid 9.1.0)
-
- Closed
-