Skip to content

Instantly share code, notes, and snippets.

@stevebooks
Created May 30, 2013 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevebooks/5679398 to your computer and use it in GitHub Desktop.
Save stevebooks/5679398 to your computer and use it in GitHub Desktop.
#Fix certificates that have a duplicate name
#Captable.where(id: 990).find_each do |cap|
Captable.find_each do |cap|
results = {}
cap.equity_certificates.find_each do |s|
puts "Cert ID: #{s.id}"
name = s.name.strip
if results.has_key?(name)
results[name] << s
else
results[name] = [s]
end
end
#remove any items that only have one item in the array (which means it is not a duplicate)
results = results.delete_if{|k,v| v.size == 1}
ap results
results.each do |k,v|
v.shift
v.each do |dup|
dup.save!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment