From 06e733d125cb331b67ac9a5a5ca0888098835fcd Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Thu, 2 Nov 2017 12:34:19 -0400 Subject: [PATCH] school merging tool --- app/models/school.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/models/school.rb b/app/models/school.rb index d869b680..07baec05 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -4,6 +4,7 @@ class School < ApplicationRecord belongs_to :district has_many :recipients, dependent: :destroy has_many :school_categories, dependent: :destroy + has_many :user_schools, dependent: :destroy validates :name, presence: true @@ -12,4 +13,14 @@ class School < ApplicationRecord include FriendlyId friendly_id :name, :use => [:slugged] + def merge_into(school) + puts "Merging #{name} (#{id}) in to #{school.name} (#{school.id})" + schedules.update_all(school: school) + recipient_lists.update_all(school: school) + recipients.update_all(school: school) + school_categories.update_all(school: school) + user_schools.update_all(school: school) + destroy + end + end