This project is archived and is in readonly mode.

#4984 ✓resolved

reset_counters doesn't work with polymorphic associations

Reported by klew | June 26th, 2010 @ 07:05 PM | in 3.0.2

If I have models:

class Phone < ActiveRecord::Base
  belongs_to :phonable, :polymorphic => true

class Person < ActiveRecord::Base
  has_many :phones, :as => :phonable

Trying to execute:

Person.reset_counters 1, :phones
NoMethodError: undefined method counter_cache_column for nil:NilClass

Problem is in this line in reset_counters method:

counter_name = child_class.reflect_on_association(

Because is not always name of belongs_to association.

Comments and changes to this ticket

Create your profile

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

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

Referenced by