# Custom counter cache

**URL:** <https://www.ruby-forum.com/t/custom-counter-cache/196698>\
**Category:** Rails\
**Created:** [June 3, 2008, 4:22pm UTC](https://www.ruby-forum.com/t/custom-counter-cache/196698 "2008-06-03T16:22:41Z")\
**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:22pm UTC](https://www.ruby-forum.com/t/custom-counter-cache/196698/1 "2008-06-03T16:22:41Z")

</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?
