/ Published in: Rails
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
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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