Class: Upgrade::RemoveDuplicateCollectionRelationsJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/upgrade/remove_duplicate_collection_relations_job.rb

Instance Method Summary collapse

Instance Method Details

#perform ⇒ Object



4
5
6
7
8
9
# File 'app/jobs/upgrade/remove_duplicate_collection_relations_job.rb', line 4

def perform
  duplicates = CollectionsModel.group("model_id", "collection_id").count.select { |ids, count| count > 1 }
  duplicates.each do |ids, count|
    CollectionsModel.where(model_id: ids[0], collection_id: ids[1]).limit(count - 1).each { |x| x.destroy }
  end
end