This project is archived and is in readonly mode.

#4984 ✓resolved
klew

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
end

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

Trying to execute:

Person.reset_counters 1, :phones
Gives:
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(self.name.downcase.to_sym).counter_cache_column

Because self.name.downcase.to_sym 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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages