commit
0c6b2c198a
@ -0,0 +1,12 @@
|
||||
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
|
@ -0,0 +1,10 @@
|
||||
class AddPraisesCountToLibraries < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :libraries, :praises_count, :integer, :default => 0
|
||||
|
||||
Library.find_each do |library|
|
||||
praises_count = library.praise_treads.count
|
||||
library.update_column(:praises_count, praises_count)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in new issue