Skip to content
Extraits de code Groupes Projets
Valider 13091426 rédigé par Raphael Sofaer's avatar Raphael Sofaer
Parcourir les fichiers

Update the Post counter caches when adding the counter cache column

parent ecd79766
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
class CounterCacheOnPostLikes < ActiveRecord::Migration
class Post < ActiveRecord::Base; end
def self.up
add_column :posts, :likes_count, :integer, :default => 0
execute <<SQL if Post.count > 0
UPDATE posts
SET posts.likes_count = (SELECT COUNT(*) FROM likes WHERE likes.post_id = posts.id)
SQL
end
def self.down
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter