mongoid/mongoid — pull request #2665 by arthurnn (2013-01-03 21:28:38+00:00)
Title: counter cache

as request on #2215 this is the counter cache implementation for mongoid.

It should work simliar as the Rails activerecord counter cache, which increment the number of children when A new children is created and has a foreign_key to its parent.

Example:
```ruby
class Person
include Mongoid::Document
has_many :pets
end

class Pet
include Mongoid::Document
belongs_to :person, counter_cache: true
end
```

```
person.pets.create! #should incremente person.pets_count

pet = Pet.new
pet.person = person
pet.save #should incremente person.pets_count

pet.destroy # should decrement person.pets_count

pet.delete # should NOT decrement person.pets_count
```

Also added some useful methods like ```Person.reset_counters(person.id, :pets)``` and ```Person.update_counters(person.id, pets_count: 5)```