Accessing ruby counter cache
        Posted  
        
            by Julian
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Julian
        
        
        
        Published on 2010-03-24T11:59:10Z
        Indexed on 
            2010/03/24
            12:03 UTC
        
        
        Read the original article
        Hit count: 599
        
ruby-on-rails
|counter-cache
Hi all,
I'm playing around with a fork of acts_as_taggable_on_steroids as a learning exercise. The version I'm looking at does some stuff I don't understand to calculate Tag counts. So I thought I'd do a version using PORC (Plain Old Rails Counters):
class Tagging < ActiveRecord::Base #:nodoc:
  belongs_to :tag, :counter_cache => "tagging_counter_cache"
...
I thought tagging_counter_cache was transparently accessed when I access tag.taggings.count but apparently not? Do I really have to access tag.tagging_counter_cache explicitly?
>> tag.taggings.count
  SQL (0.7ms)   SELECT count(*) AS count_all FROM `taggings` WHERE (`taggings`.tag_id = 16) 
Same for size.
It's cool if that's the case but just wanted to check.
© Stack Overflow or respective owner