From cb54e2aac7926df6fba49e92ebed8174507a6db5 Mon Sep 17 00:00:00 2001
From: luap42 <pstrobach15+luap42@gmail.com>
Date: Tue, 30 Jun 2020 15:26:50 +0200
Subject: [PATCH] Fix foreign key dependency issues

---
 app/models/community_user.rb | 2 ++
 app/models/user.rb           | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/app/models/community_user.rb b/app/models/community_user.rb
index 1818fe2a1..4917e529e 100644
--- a/app/models/community_user.rb
+++ b/app/models/community_user.rb
@@ -2,6 +2,8 @@ class CommunityUser < ApplicationRecord
   belongs_to :community
   belongs_to :user
 
+  has_many :mod_warnings, dependent: :destroy
+
   validates :user_id, uniqueness: { scope: [:community_id] }
 
   scope :for_context, -> { where(community_id: RequestContext.community_id) }
diff --git a/app/models/user.rb b/app/models/user.rb
index 90e41012d..aef1dd3af 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -19,6 +19,8 @@ class User < ApplicationRecord
   has_many :suggested_edits, dependent: :destroy
   has_many :suggested_edits_decided, class_name: 'SuggestedEdit', foreign_key: 'decided_by_id', dependent: :nullify
 
+  has_many :mod_warning_author, class_name: 'ModWarning', foreign_key: 'author_id', dependent: :nullify
+
   validates :username, presence: true, length: { minimum: 3, maximum: 50 }
   validates :login_token, uniqueness: { allow_nil: true, allow_blank: true }
   validate :no_links_in_username
-- 
GitLab