# Counter cache

**URL:** <https://www.ruby-forum.com/t/counter-cache/112608>\
**Category:** Rails\
**Created:** [August 21, 2007, 11:34am UTC](https://www.ruby-forum.com/t/counter-cache/112608 "2007-08-21T11:34:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fmardini](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e19adc/32.png) [@fmardini](https://www.ruby-forum.com/u/fmardini)\
**Post date:** [August 21, 2007, 11:34am UTC](https://www.ruby-forum.com/t/counter-cache/112608/1 "2007-08-21T11:34:01Z")

</div>

Hi,  
I have two models, employees and departments, and i am using  
counter\_cache to count the number of employees in a department.  
This works great, but employees can change their departments, and the  
counter cache does not get updated to reflect this.  
Is their a built in way to do this, or do i have to implement my own  
before\_save hook

thanks
