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.
educoder/db/migrate/20200106092135_modify_viewe...

11 lines
296 B

class ModifyViewedCountForSubjects < ActiveRecord::Migration[5.2]
def change
subjects = Subject.where(status: 2).includes(:shixuns)
subjects.find_each do |subject|
subject.update_attribute(:visits, subject.visits + subject.shixuns.pluck(:myshixuns_count).sum)
end
end
end