-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Persistence
-
None
class Parent include Mongoid::Document has_many :children, autosave: true end class Child include Mongoid::Document belongs_to :parent end parent = Parent.new child = Child.new child.with(collection: 'other-children') do |child| parent.with(collection: 'other-parents') do |parent| child.parent = parent parent.save! end end
This code will generate following commands:
{"insert"=>"other-parents", "ordered"=>true, "documents"=>[{"_id"=>BSON::ObjectId('61545d4dc08a6e73ddd9f1dd')}], "$db"=>"mg_blog_test", "lsid"=>{"id"=><BSON::Binary:0x10680 type=uuid data=0x07adf65b5a2f43ae...>}} {"insert"=>"other-parents", "ordered"=>true, "documents"=>[{"_id"=>BSON::ObjectId('61545d4dc08a6e73ddd9f1dc'), "parent_id"=>BSON::ObjectId('61545d4dc08a6e73ddd9f1dd')}], "$db"=>"mg_blog_test", "lsid"=>{"id"=><BSON::Binary:0x10680 type=uuid data=0x07ad...
We can see that both documents are inserted into other-parents collection, while there should be one insertion into other-parents, and one into other-children.