Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-1517

belongs_to/has_many - duplicate insert problem

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.4.0
    • Affects Version/s: None
    • Component/s: None

      class Foo
        include Mongoid::Document
        has_many :bars
      end
      class Bar
        include Mongoid::Document
        belongs_to :foo
      end
      
      f = Foo.create!
       => #<Foo _id: 4ef07b860bed3f9672000001, _type: nil> 
      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            bensymonds Ben Symonds
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: