mongoid/mongoid — Issue #1516: belongs_to/has_many - duplicate insert problem
Author: bensymonds
Created: 2011-12-21 13:47:05+00:00
State: open

```ruby
class Foo
include Mongoid::Document
has_many :bars
end
class Bar
include Mongoid::Document
belongs_to :foo
end

f = Foo.create!
=> #
Bar.create! :foo => f
Mongo::OperationFailure: 11000: E11000 duplicate key error index: blah_development.bars.$_id_ dup key: { : ObjectId('4ef07b8a0bed3f9672000002') }
```

When Mongoid tries to persist the `Bar` object, it ends up doing the insert twice, breaking the unique index on `_id`. This is with mongoid v2.3.4, driver v1.5.2.