From 907098619b9e547fde8976173230ca9db4cce04e Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 23 May 2024 17:39:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dissue=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 8 ++++++-- app/models/pm_link.rb | 7 +++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 764708546..e7e15f4a7 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -94,7 +94,7 @@ class Issue < ApplicationRecord has_many :attach_pull_requests, through: :pull_attached_issues, source: :pull_request # PM 关联工作项目 has_many :pm_links, as: :linkable, dependent: :destroy - has_many :be_pm_links,as: :be_linkable, dependent: :destroy + belongs_to :changer, class_name: 'User', foreign_key: :changer_id, optional: true scope :issue_includes, ->{includes(:user)} @@ -107,7 +107,11 @@ class Issue < ApplicationRecord after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic before_save :check_pm_and_update_due_date after_save :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container, :generate_uuid - after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic + after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic, :destroy_be_pm_links + + def destroy_be_pm_links + PmLink.where(be_linkable_type:"Issue",be_linkable_id:self.id).map(&:destroy) + end def check_pm_and_update_due_date if pm_project_id.present? && pm_issue_type.present? && status_id_changed? diff --git a/app/models/pm_link.rb b/app/models/pm_link.rb index 0e7d56b59..91962bf7b 100644 --- a/app/models/pm_link.rb +++ b/app/models/pm_link.rb @@ -18,9 +18,8 @@ class PmLink < ApplicationRecord belongs_to :linkable, polymorphic: true - belongs_to :be_linkable, polymorphic: true - # def be_linkable - # be_linkable_type.constantize.find be_linkable_id - # end + def be_linkable + be_linkable_type.constantize.find be_linkable_id + end end