YarikHrom

Untitled

Jun 15th, 2022 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.57 KB | None | 0 0
  1. #collect all duplicated hard skills
  2. duplicated_hard_skills = HardSkill.where.not(id: HardSkill.group(:name).select("min(id)"))
  3.  
  4. #go through the array of employees with duplicated hard skills and change hard_skill_id
  5. EmployeeHardSkill.where(hard_skill_id: duplicated_hard_skills).each do  |ehs|
  6.     original_name = HardSkill.find(ehs.hard_skill_id).name
  7.     original_id = HardSkill.find_by(name: original_name).id
  8.     ehs.update(hard_skill_id: original_id)
  9. end
  10.  
  11. #delete all duplicated hard skills
  12. HardSkill.where.not(id: HardSkill.group(:name).select("min(id)")).destroy_all
Add Comment
Please, Sign In to add comment