diff --git a/app/models/group.rb b/app/models/group.rb index d0dcf51..22f3dac 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -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 diff --git a/lib/tasks/maintenance.rake b/lib/tasks/maintenance.rake index 496063e..276481d 100644 --- a/lib/tasks/maintenance.rake +++ b/lib/tasks/maintenance.rake @@ -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"