#2 ✓resolved
Will Bunker

Issue when adding a counter cache column

Reported by Will Bunker | February 16th, 2009 @ 04:34 PM

The rate_average function was returning an infinity when using rates_count cached column. It was using the old number before the model updated it. I fixed it by adding the following code to the update_cached_average function:

rates(:refresh).size if self.respond_to?(:rates_count)

full function is now:

def update_cached_average
  if self.class.caching_average?
    rates(:refresh).size if self.respond_to?(:rates_count)
    send("#{self.class.options[:cache_column]}=", self.rate_average(false))
    save!
  end
end

end

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Rails plugin to generate a simple and nice rating system ajaxly.

http://github.com/edgarjs/ajaxful-rating

People watching this ticket

Pages