---
date: "2014-11-21"
---

Let the database do all of the heavy lifting for counting your ActiveRecord objects.

```ruby
Record.pluck(:owner_id).each_with_object(Hash.new(0)) { |id, counts|
  counts[id] += 1
}
```

Sums up the number of records for a `owner` in Ruby. The same can be achieved via ActiveRecord.

```ruby
Record.group(:owner_id).count
```
