Return to Snippet

Revision: 3350
at July 13, 2007 04:48 by bordalix


Initial Code
class AddTaskCount < ActiveRecord::Migration
  def seld.up
    add_column :projects, :tasks_count, :integer, :default => 0
    Project.reset_column_information
    Project.find(:all).each do |p|
      p.update_attribute :tasks_count, p.tasks.length
    end
  end

  def self.down
    remove_column :projects, :tasks_count
  end
end

--

class Task < ActiveRecord::Base
  belongs_to :project, :counter_cache => true
end

Initial URL

                                

Initial Description
A great way to improve the performance of your web app, by using a column in the projects table which stores the number of task associated with it, seen in railscast #23

Initial Title
Counter Cache Column

Initial Tags
cache

Initial Language
Rails