class ModifyPraisesCountForDiscuess < ActiveRecord::Migration[5.2] def change discusses = Discuss.includes(:praise_treads).unscoped discusses.find_each do |d| praises_count = d.praise_treads.liker.count d.update_column(:praises_count, praises_count) end end end