10 lines
342 B
Ruby
10 lines
342 B
Ruby
class AddCommentsCountToTracks < ActiveRecord::Migration[5.1]
|
|
def change
|
|
add_column :tracks, :comments_count, :integer, default: 0, null: false
|
|
|
|
Track.find_each do |track|
|
|
comments_count = track.comment_threads.count
|
|
track.update_attributes(:comments_count, comments_count) unless comments_count.zero?
|
|
end
|
|
end
|
|
end
|