Attribute accessor (counter_cache)


#1

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