mongoid/mongoid — pull request #3638 by uiureo (2014-05-08 08:07:42+00:00)
Title: Bug?: has_and_belongs_to_many relations with primary_key

Example:
``` ruby
class FireHydrant
include Mongoid::Document
field :location, type: String
has_and_belongs_to_many :dogs, primary_key: :name
end

class Dog
include Mongoid::Document
field :name, type: String
has_and_belongs_to_many :fire_hydrants, primary_key: :location
end
```

``` ruby
fire_hydrant_one = FireHydrant.create(location: 'one')
fire_hydrant_two = FireHydrant.create(location: 'two')

dog.fire_hydrants = [fire_hydrant_one]
dog.fire_hydrant_ids #=> ['one']

dog.fire_hydrants = [fire_hydrant_one, fire_hydrant_two]
dog.fire_hydrant_ids
#=> [BSON::ObjectId('536b3a7a43616e1592e10300'), BSON::ObjectId('536b3a7a43616e1592e20300')]
```

I added tests to reproduce this behavior.