# Custom counter cache

**URL:** <https://www.ruby-forum.com/t/custom-counter-cache/139405>\
**Category:** Rails\
**Created:** [June 3, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/custom-counter-cache/139405 "2008-06-03T16:20:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dmitrij\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dfb087/32.png) [@Dmitrij\_S](https://www.ruby-forum.com/u/Dmitrij_S)\
**Post date:** [June 3, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/custom-counter-cache/139405/1 "2008-06-03T16:20:55Z")

</div>

class Category  
has\_many :tracks  
end

class Track  
belongs\_to :category, :counter\_cache =\> true

named\_scope :converted, :conditions =\> {:converted =\> true}  
named\_scope :active, :conditions =\> {:active =\> true}  
end

I want to make custom counters for scoped associations, e.g:

category.converted\_tracks\_count  
category.active\_tracks\_count

And when `track` changes its converted, active, and category\_id status  
counters must be updated.

Any suggestions?
