mongoid/mongoid — pull request #2809 by arthurnn (2013-02-11 03:01:30+00:00)
Title: Custom keys for associations #1850

Relations now have one more option, ```primary_key```

Given those models
```ruby
class Person
include Mongoid::Document

field :username
has_many :cats, primary_key: :username
end
```

```ruby
class Cat
include Mongoid::Document

field :name
belongs_to :person, primary_key: :username
end
```

```ruby
crazy_lady = Person.create!
20.times { crazy_lady.cats.create! }
```

this will create 20 cats, and the fk, on Cat, ```person_id```, will be the username.