Skip to content

Commit

Permalink
fix the merge duplicates code
Browse files Browse the repository at this point in the history
  • Loading branch information
johnofsydney committed Nov 12, 2024
1 parent 82456b9 commit 7598e7e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ def is_category? = category?
def merge_into(replacement_group)
# TODO - also update all the transfers
Membership.where(member: self).update_all(member_id: replacement_group.id)
Membership.where(group: self).update_all(group_id: replacement_group.id)
Transfer.where(giver: self).update_all(giver_id: replacement_group.id)
Transfer.where(taker: self).update_all(taker_id: replacement_group.id)

self.destroy
end
Expand Down
6 changes: 5 additions & 1 deletion lib/tasks/maintenance.rake
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ namespace :lester do
end

desc "Remove Duplicates"
task remove_duplicates: :environment do
task merge_duplicates: :environment do
## MERGING EXAMPLE ##
# ey = Group.find_by(name: 'EY')
# ernst_and_young = Group.find_by(name: 'Ernst & Young')
# ey.merge_into(ernst_and_young)

ralph_party = Group.find_by(name: 'United Australia Federal')
clive_party = Group.find_by(name: 'United Australia Party')
ralph_party.merge_into(clive_party)
end

desc "Add time range for party memberships"
Expand Down

0 comments on commit 7598e7e

Please sign in to comment.