Sha256: e99d07c7f14753ed9a256a3e7261c87dc7f5bab862cf9f91cf7c372487fd13fe
Contents?: true
Size: 988 Bytes
Versions: 30
Compression:
Stored size: 988 Bytes
Contents
class Bare33Content < ActiveRecord::Base include BareMigration def count_children_of_type(type) self.class.find(:all, :conditions => ["article_id = ? and type = ?", self.id, type ]).size end def correct_counts self.comments_count = self.count_children_of_type('Comment') self.trackbacks_count = self.count_children_of_type('Trackback') end end class AddCountCaching < ActiveRecord::Migration def self.up STDERR.puts "Adding comments_count, trackbacks_count" modify_tables_and_update([:add_column, Bare33Content, :comments_count, :integer], [:add_column, Bare33Content, :trackbacks_count, :integer]) do |a| if not $schema_generator a.correct_counts end end end def self.down STDERR.puts "Removing counts columns" remove_column :contents, :comments_count remove_column :contents, :trackbacks_count end end
Version data entries
30 entries across 30 versions & 1 rubygems