From d6ddfff11fa2f3cc8d5f980ec594886a5a76d317 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Fri, 7 Jan 2022 11:38:53 +0100
Subject: [PATCH] declare some associations & git deps on program

---
 app/models/education/program.rb | 17 +++++++++++++----
 app/models/university/person.rb |  5 ++++-
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/app/models/education/program.rb b/app/models/education/program.rb
index 4ab6b5127..ba085aa57 100644
--- a/app/models/education/program.rb
+++ b/app/models/education/program.rb
@@ -67,12 +67,18 @@ class Education::Program < ApplicationRecord
   has_many   :teachers,
              class_name: 'Education::Program::Teacher',
              dependent: :destroy
-  has_many   :people,
+  has_many   :university_people_through_teachers,
              through: :teachers,
-             dependent: :destroy
+             source: :person
   has_many   :roles,
              class_name: 'Education::Program::Role',
              dependent: :destroy
+  has_many   :role_people,
+             through: :roles,
+             source: :person
+  has_many   :university_people_through_roles,
+             through: :role_people,
+             source: :person
   has_many   :website_categories,
              class_name: 'Communication::Website::Category',
              dependent: :destroy
@@ -115,8 +121,11 @@ class Education::Program < ApplicationRecord
   end
 
   def git_dependencies_static
-    # TODO: Add Teacher & Role::Person
-    active_storage_blobs
+    [
+      active_storage_blobs,
+      university_people_through_teachers,
+      university_people_through_roles
+    ].flatten.uniq.compact
   end
 
   def git_destroy_dependencies_static
diff --git a/app/models/university/person.rb b/app/models/university/person.rb
index 481511e1b..558d22a93 100644
--- a/app/models/university/person.rb
+++ b/app/models/university/person.rb
@@ -43,7 +43,10 @@ class University::Person < ApplicationRecord
 
   has_many                :education_program_teachers,
                           class_name: 'Education::Program::Teacher',
-                          foreign_key: :person_id,
+                          dependent: :destroy
+
+  has_many                :education_program_role_people,
+                          class_name: 'Education::Program::Role::Person',
                           dependent: :destroy
 
   has_many                :education_programs,
-- 
GitLab