From 4f5cfe6a0814d3ba20952acf9e0daa42404fbd57 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Fri, 2 Dec 2022 15:59:14 +0100
Subject: [PATCH] association

---
 app/models/communication/website/previous_link.rb     | 5 +++++
 app/models/communication/website/with_dependencies.rb | 4 ++++
 2 files changed, 9 insertions(+)

diff --git a/app/models/communication/website/previous_link.rb b/app/models/communication/website/previous_link.rb
index b099d84c6..44ca9255e 100644
--- a/app/models/communication/website/previous_link.rb
+++ b/app/models/communication/website/previous_link.rb
@@ -30,10 +30,15 @@ class Communication::Website::PreviousLink < ApplicationRecord
   belongs_to :about, polymorphic: true
 
   before_validation :set_university, on: :create
+  after_destroy_commit :sync_about
 
   private
 
   def set_university
     self.university_id = website.university_id
   end
+
+  def sync_about
+    about.sync_with_git
+  end
 end
diff --git a/app/models/communication/website/with_dependencies.rb b/app/models/communication/website/with_dependencies.rb
index 6bb58aae9..255087ad3 100644
--- a/app/models/communication/website/with_dependencies.rb
+++ b/app/models/communication/website/with_dependencies.rb
@@ -23,6 +23,10 @@ module Communication::Website::WithDependencies
                 foreign_key: :communication_website_id,
                 dependent: :destroy
 
+    has_many    :previous_links,
+                class_name: "Communication::Website::PreviousLink",
+                dependent: :destroy
+
   end
 
   def blocks
-- 
GitLab