You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
13 lines
387 B
13 lines
387 B
class AddPraisesCountToMemos < ActiveRecord::Migration[5.2]
|
|
def change
|
|
add_column :memos, :praises_count, :integer, :default => 0
|
|
|
|
memos = Memo.includes(:praise_treads).all
|
|
memos.find_each do |m|
|
|
puts("####{m.id}")
|
|
praises_count = m.praise_treads.select{|pt| pt.praise_or_tread == 1}.count
|
|
m.update_column(:praises_count, praises_count)
|
|
end
|
|
end
|
|
end
|