Migration: counter cache & "reset_column_information"


#1

To speed up

<%= @project.members_count %>

, I added a counter cache to the ‘projects’ table with the migration
below:

def self.up
add_column “projects”, “members_count”, :string, :default => “0”
Project.reset_column_information
Project.find(:all).each do |p|
p.update_attribute :members_count , p.members.count
end
end

Question:
Is “Project.reset_column_information” required in the migration?

Alain

(Note: For info, I modified the ‘Member’ model accordingly:
class Member < ActiveRecord::Base
belongs_to :project, :counter_cache => true
)


#2

Anybody?