-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
If you have a document that's embedded 2 levels deep and is part of an "embeds many" relation, its fields aren't updated. This is using Mongoid 2.3.0 .
class Level1 include Mongoid::Document embeds_many :level2s end class Level2 include Mongoid::Document embedded_in :level1 embeds_many :level3s end class Level3 include Mongoid::Document embedded_in :level2 field :name, :type => String end Level1.delete_all level1 = Level1.new level1.level2s.new level1.level2s.last.level3s.new :name => 'level 3' level1.save puts "Level 3 name: #{Level1.last.level2s.last.level3s.last.name}" level1 = Level1.last level1.level2s.last.level3s.last.name = 'level 3 updated' level1.save puts "Level 3 name: #{Level1.last.level2s.last.level3s.last.name}" level1 = Level1.last level1.level2s.last.level3s.last.update_attribute :name, 'level 3 updated again' puts "Level 3 name: #{Level1.last.level2s.last.level3s.last.name}"
produces this output:
Level 3 name: level 3 Level 3 name: level 3 Level 3 name: level 3