Revisions
-
terrellt revised this gist
Jun 25, 2013 . 2 changed files with 9 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,7 @@ class UpdateCache < ActiveRecord::Migration def up User.all.each do |user| User.reset_counters(user.id, :pets) end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,16 +13,15 @@ ** [out :: ] ** [out :: ] /var/www/Test/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/reflection.rb:172:in `klass' ** [out :: ] ** [out :: ] /var/www/Test/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/counter_cache.rb:33:in `block in res et_counters' ** [out :: ] ** [out :: ] /var/www/Test/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/counter_cache.rb:19:in `each' ** [out :: ] ** [out :: ] /var/www/Test/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/counter_cache.rb:19:in `reset_counte rs' ** [out :: ] ** [out :: ] /var/www/Test/releases/20130625071422/db/migrate/20130625055633_update_cache.rb:4:in `block in up' ** [out :: ] ** [out :: ] /var/www/Test/releases/20130625071422/db/migrate/20130625055633_update_cache.rb:3:in `each' ** [out :: ] -
terrellt revised this gist
Jun 25, 2013 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ def up User.all.each do |user| object = user association = :pets counter_name = :pets_count User.connection.update("UPDATE #{User.quoted_table_name} SET #{User.connection.quote_column_name(counter_name)} = #{object.pets.count} WHERE #{User.connection.quote_column_name(User.primary_key)} = #{User.quote_value(object.id)}", "#{User.name} UPDATE") end end -
terrellt revised this gist
Jun 25, 2013 . 1 changed file with 27 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,28 @@ servers: [""] [] executing command ** [out :: ] == UpdateCache: migrating ==================================================== ** [out :: ] ** [out :: ] rake aborted! ** [out :: ] ** [out :: ] An error has occurred, this and all later migrations canceled: ** [out :: ] ** [out :: ] ** [out :: ] uninitialized constant User::Pet ** [out :: ] /var/www/Test/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/inheritance.rb:111:in `compute_type' ** [out :: ] ** [out :: ] /var/www/Test/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/reflection.rb:172:in `klass' ** [out :: ] ** [out :: ] /var/www/Test/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/associations/association.rb:117:in ` klass' ** [out :: ] ** [out :: ] /var/www/Test/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/associations/association.rb:123:in ` target_scope' ** [out :: ] ** [out :: ] /var/www/Test/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/associations/association.rb:87:in `s coped' ** [out :: ] ** [out :: ] /var/www/Test/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/associations/collection_association. rb:210:in `count' ** [out :: ] ** [out :: ] /var/www/Test/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/associations/collection_proxy.rb:46: -
terrellt revised this gist
Jun 25, 2013 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,9 @@ class UpdateCache < ActiveRecord::Migration def up User.all.each do |user| object = user association = :pets User.connection.update("UPDATE #{User.quoted_table_name} SET #{User.connection.quote_column_name(counter_name)} = #{object.pets.count} WHERE #{User.connection.quote_column_name(User.primary_key)} = #{User.quote_value(object.id)}", "#{User.name} UPDATE") end end -
terrellt revised this gist
Jun 25, 2013 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
terrellt revised this gist
Jun 25, 2013 . 2 changed files with 22 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :confirmable validates :email, :presence => true, :uniqueness => true validates :username, :presence => true, :uniqueness => true # Pets has_many :pets, :foreign_key => :owner_id # @return [Pet] Active pet for this user. def active_pet self.pets.length > 0 ? self.pets[0] : nil end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ class Pet < ActiveRecord::Base belongs_to :owner, :class_name => "User", :counter_cache => true validates :owner, :presence => true end -
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ class UpdatePetsCache < ActiveRecord::Migration def up User.all.each do |user| User.reset_counters user.id, :pets end end def down end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ [out :: ] == UpdatePetsCache: migrating ================================================ [out :: ] [out :: ] rake aborted! [out :: ] [out :: ] An error has occurred, this and all later migrations canceled: [out :: ] [out :: ] [out :: ] uninitialized constant User::Pet [out :: ] /var/www/Test/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/inheritance.rb:111:in `compute_type' [out :: ] [out :: ] /var/www/Test/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/reflection.rb:172:in `klass' [out :: ] [out :: ] /var/www/Test/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/counter_cache.rb:33:in `block in res ounters' [out :: ] [out :: ] /var/www/Test/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/counter_cache.rb:19:in `each' [out :: ] [out :: ] /var/www/Test/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/counter_cache.rb:19:in `reset_counte