From f81bd6bffbdc84fb752542b67d4c4f0138feae81 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 12 Sep 2024 09:12:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=9F=90=E4=B8=AA?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=97=A0=E6=B3=95=E8=AF=86=E5=88=AB=E5=A4=9A?= =?UTF-8?q?=E6=80=81=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 3 ++- app/models/pm_link.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index d7890e15..f6dfd39b 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -144,7 +144,8 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end end p.workbook.add_worksheet(:name => 'link_relations') do |sheet| - links = PmLink.joins(:linkable_issue).where(issues: {pm_project_id: params[:pm_project_id]}) + # links = PmLink.joins(:linkable_issue).where(issues: {pm_project_id: params[:pm_project_id]}) + links = PmLink.find_by_sql("SELECT `pm_links`.* FROM `pm_links` INNER JOIN `issues` ON `issues`.`id` = `pm_links`.`linkable_id` AND `pm_links`.`linkable_type` = 'Issue' WHERE `issues`.`pm_project_id` = #{params[pm_project_id]}") sheet.add_row ["ID", "被关联工作项ID"] links.each do |link| sheet.add_row [link.linkable_id, link.be_linkable_id] diff --git a/app/models/pm_link.rb b/app/models/pm_link.rb index e4557815..d9d9a789 100644 --- a/app/models/pm_link.rb +++ b/app/models/pm_link.rb @@ -19,8 +19,8 @@ class PmLink < ApplicationRecord belongs_to :linkable, polymorphic: true belongs_to :be_linkable, polymorphic: true - belongs_to :linkable_issue, -> {where(pm_links: {linkable_type: 'Issue'})}, foreign_key: 'linkable_id', class_name: 'Issue' - belongs_to :be_linkable_issue, -> {where(pm_links: {be_linkable_type: 'Issue'})}, foreign_key: 'be_linkable_id', class_name: 'Issue' + # belongs_to :linkable_issue, -> {where(pm_links: {linkable_type: 'Issue'})}, foreign_key: 'linkable_id', class_name: 'Issue' + # belongs_to :be_linkable_issue, -> {where(pm_links: {be_linkable_type: 'Issue'})}, foreign_key: 'be_linkable_id', class_name: 'Issue' def be_linkable be_linkable_type.constantize.find be_linkable_id