summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-10-01 09:46:34 -0400
committerFrederic Guillot <fred@kanboard.net>2015-10-01 09:46:34 -0400
commit370361330aeb37f02e87ab78ae38521da774c957 (patch)
treedafef9c946d278a9acc99947af6212bb5c25f1c0
parent792d5a20bcb4926c91311afced67ddd008c3b79e (diff)
Fix Postgres issue "Cardinality violation" when there is multiple "is_milestone_of" links
-rw-r--r--ChangeLog1
-rw-r--r--app/Model/TaskFinder.php2
-rw-r--r--tests/units/Model/TaskLinkTest.php21
3 files changed, 23 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 9675a8e1..0e36e9d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -50,6 +50,7 @@ Bug fixes:
* Deleting subtask doesn't update task time tracking
* Fix Mysql error about gitlab_id when creating remote user
* Fix subtask timer bug (event called recursively)
+* Fix Postgres issue "Cardinality violation" when there is multiple "is_milestone_of" links
Version 1.0.18
--------------
diff --git a/app/Model/TaskFinder.php b/app/Model/TaskFinder.php
index e9735d81..9e76e62e 100644
--- a/app/Model/TaskFinder.php
+++ b/app/Model/TaskFinder.php
@@ -93,7 +93,7 @@ class TaskFinder extends Base
'(SELECT count(*) FROM '.Subtask::TABLE.' WHERE '.Subtask::TABLE.'.task_id=tasks.id) AS nb_subtasks',
'(SELECT count(*) FROM '.Subtask::TABLE.' WHERE '.Subtask::TABLE.'.task_id=tasks.id AND status=2) AS nb_completed_subtasks',
'(SELECT count(*) FROM '.TaskLink::TABLE.' WHERE '.TaskLink::TABLE.'.task_id = tasks.id) AS nb_links',
- '(SELECT 1 FROM '.TaskLink::TABLE.' WHERE '.TaskLink::TABLE.'.task_id = tasks.id AND '.TaskLink::TABLE.'.link_id = 9) AS is_milestone',
+ '(SELECT DISTINCT 1 FROM '.TaskLink::TABLE.' WHERE '.TaskLink::TABLE.'.task_id = tasks.id AND '.TaskLink::TABLE.'.link_id = 9) AS is_milestone',
'tasks.id',
'tasks.reference',
'tasks.title',
diff --git a/tests/units/Model/TaskLinkTest.php b/tests/units/Model/TaskLinkTest.php
index 1e79ea74..fed03334 100644
--- a/tests/units/Model/TaskLinkTest.php
+++ b/tests/units/Model/TaskLinkTest.php
@@ -3,12 +3,33 @@
require_once __DIR__.'/../Base.php';
use Model\Link;
+use Model\TaskFinder;
use Model\TaskLink;
use Model\TaskCreation;
use Model\Project;
class TaskLinkTest extends Base
{
+ // Check postgres issue: "Cardinality violation: 7 ERROR: more than one row returned by a subquery used as an expression"
+ public function testGetTaskWithMultipleMilestoneLink()
+ {
+ $tf = new TaskFinder($this->container);
+ $tl = new TaskLink($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'C')));
+
+ $this->assertNotFalse($tl->create(1, 2, 9));
+ $this->assertNotFalse($tl->create(1, 3, 9));
+
+ $task = $tf->getExtendedQuery()->findOne();
+ $this->assertNotEmpty($task);
+ }
+
public function testCreateTaskLinkWithNoOpposite()
{
$tl = new TaskLink($this->container);