This project is archived and is in readonly mode.

#3367 ✓stale
Arj

using touch on a parent model prevents counter_cache from working

Reported by Arj | October 12th, 2009 @ 02:28 PM

Given the following code


Class Topic
  has_many :posts
end

Class Post
  belongs_to :topic, :counter_cache => true

  after_create :touch_topic

  def touch_topic
    self.topic.touch
  end
end

The touch action in the after_create prevents the counter_cache from incrementing the :posts_count on the topic when a post is created. Commenting out the self.topic.touch lets counter_cache work again.

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>

Pages