RubyFlow : The Ruby Community Blog

Home   Submit   Sign Up   Log In   leaders   Twitter   RSS Feed  
 

Optimizing Active Record Associated Record Count Queries With the belongs_to counter_cache Option

It is often useful to know how many records are associated with a model identified as being the parent in a belongs_to relationship. Active Record's default behavior is to determine this number using a COUNT(*) query. Fortunately, you can avoid this additional costly query by caching the associated record account with a few simple modifications to your Rails application. Read the tutorial.

Comments

Post a Comment

Comment abilities for non registered users are currently deactivated, pending time to add a proper CAPTCHA to solve the escalating spam problem. Sorry!