迁移点赞数据

dev_course
daiao 6 years ago
parent 13876033a2
commit 234cdbeab9

@ -0,0 +1,12 @@
class AddPraisesCountForChallenges < ActiveRecord::Migration[5.2]
def change
add_column :challenges, :praises_count, :integer, :default => 0
challenges = Challenge.where(nil)
challenges.each do |c|
praises_count = c.praise_tread.where(praise_or_tread: 1).count
c.update_column(:praises_count, praises_count)
end
end
end
Loading…
Cancel
Save