From bfaf0541979a8263f27c3ff4501def75273a4cb6 Mon Sep 17 00:00:00 2001 From: liugang Date: Fri, 12 Dec 2025 09:52:07 +0800 Subject: [PATCH] * [refac] Fix Integrity constraint violatioin: 1052 Column 'xxx' in ORDER BY is ambiguous. --- module/story/model.php | 3 +++ module/story/tao.php | 3 +++ module/testcase/model.php | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/module/story/model.php b/module/story/model.php index 6c27ee8b2b..1520e73c0b 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -375,6 +375,9 @@ class storyModel extends model $branchParam = ($type == 'bybranch' and $param !== '') ? $param : (string)$this->cookie->storyBranchParam; + if(strpos($orderBy, 'version_') !== false) $orderBy = str_replace('id_', 't2.version_', $orderBy); + if(strpos($orderBy, 'id_') !== false) $orderBy = str_replace('id_', 't2.id_', $orderBy); + $stories = $this->dao->select("distinct t1.*, t2.`path`, t2.`plan`, t2.*, IF(t2.`pri` = 0, {$this->config->maxPriValue}, t2.`pri`) as priOrder, t3.type as productType, t2.version as version")->from(TABLE_PROJECTSTORY)->alias('t1') ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id') ->leftJoin(TABLE_PRODUCT)->alias('t3')->on('t2.product = t3.id') diff --git a/module/story/tao.php b/module/story/tao.php index d59c2e5880..7330d7c427 100644 --- a/module/story/tao.php +++ b/module/story/tao.php @@ -400,6 +400,9 @@ class storyTao extends storyModel $hasExecution = strpos($storyQuery, 't2.`execution`') !== false; if($hasExecution) $storyQuery = str_replace('t2.`execution`', 't1.`project`', $storyQuery); + if(strpos($orderBy, 'version_') !== false) $orderBy = str_replace('id_', 't2.version_', $orderBy); + if(strpos($orderBy, 'id_') !== false) $orderBy = str_replace('id_', 't2.id_', $orderBy); + return $this->dao->select("distinct t1.*, t2.*, IF(t2.`pri` = 0, {$this->config->maxPriValue}, t2.`pri`) as priOrder, t3.type as productType, t2.version as version")->from(TABLE_PROJECTSTORY)->alias('t1') ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id') ->leftJoin(TABLE_PRODUCT)->alias('t3')->on('t2.product = t3.id') diff --git a/module/testcase/model.php b/module/testcase/model.php index 691343577e..c7d5656c14 100755 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -140,6 +140,10 @@ class testcaseModel extends model { if(common::isTutorialMode()) return $this->loadModel('tutorial')->getCases(); + if(strpos($orderBy, 'id_') !== false) $orderBy = str_replace('id_', 't2.id_', $orderBy); + if(strpos($orderBy, 'order_') !== false) $orderBy = str_replace('order_', 't2.order_', $orderBy); + if(strpos($orderBy, 'version_') !== false) $orderBy = str_replace('version_', 't2.version_', $orderBy); + if($browseType == 'needconfirm') { return $this->dao->select('distinct t1.*, t2.*')->from(TABLE_PROJECTCASE)->alias('t1')