Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

using touch on a parent model prevents counter_cache from working

#3367

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.

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

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to stale
    • Importance changed from to

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

    October 6th, 2010 @ 06:40 AM

  2. bingbing