# Counter cache for average

**URL:** <https://www.ruby-forum.com/t/counter-cache-for-average/103549>\
**Category:** Rails\
**Created:** [May 7, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/counter-cache-for-average/103549 "2007-05-07T20:27:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rlwinter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecccb3/32.png) [@rlwinter](https://www.ruby-forum.com/u/rlwinter)\
**Post date:** [May 7, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/counter-cache-for-average/103549/1 "2007-05-07T20:27:47Z")

</div>

Hello list,

I’m curious if Rails has built-in support similar to :counter\_cache  
for other type of aggregate values such as average, min, max, etc?

If not, does a plugin exist that adds this functionality to Rails?

---

<div class="post-metadata">

**Author:** ![rlwinter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecccb3/32.png) [@rlwinter](https://www.ruby-forum.com/u/rlwinter)\
**Post date:** [May 8, 2007, 3:28pm UTC](https://www.ruby-forum.com/t/counter-cache-for-average/103549/2 "2007-05-08T15:28:33Z")

</div>

Apologies, but I’m afraid this may have gotten lost in the shuffle.  
Anyone have any ideas on this?

---

<div class="post-metadata">

**Author:** ![rlwinter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecccb3/32.png) [@rlwinter](https://www.ruby-forum.com/u/rlwinter)\
**Post date:** [May 8, 2007, 6:01pm UTC](https://www.ruby-forum.com/t/counter-cache-for-average/103549/3 "2007-05-08T18:01:27Z")

</div>

Robert W. wrote:

> Apologies, but I’m afraid this may have gotten lost in the shuffle.  
> Anyone have any ideas on this?

If it helps I wrote a blog post on how to write custom counter caches,  
this could easily be modified to do whatever you want…

> **[Custom counter\_cache with Conditions](https://douglasfshearer.com/2006/10/06/custom-counter-cache-with-conditions.html)**
>
> The counter cache ability of a model relationship is amongst the most useful in Rails’ Active Record repertoire. In it’s standard form it looks like this:

Hope it helps.
