-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
Mongoid: 2.2.3
Ruby: ree-1.8.7
Rails: 3.0.10
Simular with issue MONGOID-1226.
This case works fine:
class Post include Mongoid::Document embeds_many :comments end class Comment include Mongoid::Document field :text, :type => String embedded_in :post end Post.delete_all Post.create!(:comments => [{ :text => 'message 1' }]) p = Post.first p.update_attributes :comments => [{ :text => 'message 2' }] Post.first.comments.count => 1
But this works incorrectly:
class Blog include Mongoid::Document embeds_many :posts end class Post include Mongoid::Document embedded_in :blog embeds_many :comments end class Comment include Mongoid::Document field :text, :type => String embedded_in :post end Blog.delete_all Blog.create!({ :posts => [{ :comments => [{ :text => 'message 1' }] }] }) p = Blog.first.posts.first p.update_attributes :comments => [{ :text => 'message 2' }] reload! Blog.first.posts.first.comments.count => 2