# Attribute accessor (counter\_cache)

**URL:** <https://www.ruby-forum.com/t/attribute-accessor-counter-cache/89509>\
**Category:** Rails\
**Created:** [March 20, 2007, 10:22pm UTC](https://www.ruby-forum.com/t/attribute-accessor-counter-cache/89509 "2007-03-20T22:22:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@andrew](https://www.ruby-forum.com/u/andrew)\
**Post date:** [March 20, 2007, 10:22pm UTC](https://www.ruby-forum.com/t/attribute-accessor-counter-cache/89509/1 "2007-03-20T22:22:29Z")

</div>

Hello,

I am rather confused about what I’m seeing with an attribute of mine  
that has been defined as a counter\_cache.

‘votes\_count’ is the attribute that is a counter\_cache var.

If I do this in my view…

\<% p test.attributes %\>  
\<% p test[:votes\_count] %\>  
\<% p test.votes\_count %\>

I get this printed out…

{“votes\_count”=\>11, “id”=\>2}  
11  
1

Why does test.votes\_count give me 1?

If I do a test.reload before calling those prints, then test.votes\_count  
gives me the correct value of 11.

Can somebody tell me why I’m seeing these results?

Thanks,  
Andrew
