修改迁移文件
This commit is contained in:
parent
aa508f713c
commit
fe0e2be00e
|
@ -1,11 +1,12 @@
|
||||||
class ChangeProjectWatchersCount < ActiveRecord::Migration[5.2]
|
class ChangeProjectWatchersCount < ActiveRecord::Migration[5.2]
|
||||||
|
#修改project的watchers_count 不正确的问题
|
||||||
def change
|
def change
|
||||||
watcher_ids = Watcher.where(watchable_type: "Project").pluck(:watchable_id).uniq
|
watcher_ids = Watcher.where(watchable_type: "Project").pluck(:watchable_id).uniq
|
||||||
watcher_ids.each do |i|
|
watcher_ids.each do |i|
|
||||||
puts "#######____update_project_watchers_id____##############{i}"
|
puts "#######____update_project_watchers_id____##############{i}"
|
||||||
p = Project.includes(:watchers).select(:id, :watchers_count).find_by(i)
|
p = Project.includes(:watchers).select(:id, :watchers_count).find_by(i)
|
||||||
if p.present?
|
if p.present?
|
||||||
p.update_attribute(:watchers_count, p.watchers.size)
|
Project.reset_counters(i, :watchers)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue