From 10ac64c574c568bb8f5b771ba76d4e01411ab3b7 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sat, 13 May 2017 19:26:43 -0700 Subject: [PATCH] before destroy callback on maps to remove source_id foreign key relations (#1119) --- app/models/map.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/map.rb b/app/models/map.rb index dd5e5604..76fddcd8 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -42,6 +42,7 @@ class Map < ApplicationRecord after_create :after_created after_update :after_updated after_save :update_deferring_topics_and_synapses, if: :permission_changed? + before_destroy :before_destroyed delegate :count, to: :topics, prefix: :topic # same as `def topic_count; topics.count; end` delegate :count, to: :synapses, prefix: :synapse @@ -158,4 +159,10 @@ class Map < ApplicationRecord end end handle_asynchronously :after_updated_async + + def before_destroyed + Map.where(source_id: id).find_each do |forked_map| + forked_map.update(source_id: nil) + end + end end