scinote-web/db/migrate/20160513143117_refresh_assigned_samples_counters.rb

15 lines
409 B
Ruby
Raw Normal View History

2017-06-30 16:23:28 +08:00
class RefreshAssignedSamplesCounters < ActiveRecord::Migration[4.2]
2016-07-21 19:11:15 +08:00
def up
# Reset the counters for assigned samples
if defined?(Sample)
Sample.find_each do |sample|
sample.update(nr_of_modules_assigned_to: sample.my_modules.count)
end
2016-07-21 19:11:15 +08:00
MyModule.find_each do |my_module|
my_module.update(nr_of_assigned_samples: my_module.samples.count)
end
2016-07-21 19:11:15 +08:00
end
end
end