From 9ebec002cd1e844576e52f004201de91fd3113f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Wed, 4 Mar 2020 20:35:10 -0800 Subject: [PATCH] Fix regression with MySQL Fixes #4430 and #4431 --- app/Model/ProjectModel.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Model/ProjectModel.php b/app/Model/ProjectModel.php index 74b91d172..683d20ff6 100644 --- a/app/Model/ProjectModel.php +++ b/app/Model/ProjectModel.php @@ -89,11 +89,15 @@ class ProjectModel extends Base public function getByIdWithOwnerAndTaskCount($project_id) { return $this->db->table(self::TABLE) - ->columns(self::TABLE.'.*', UserModel::TABLE.'.username AS owner_username', UserModel::TABLE.'.name AS owner_name', 'SUM(CAST('.TaskModel::TABLE.'.is_active AS INTEGER)) AS nb_active_tasks') + ->columns( + self::TABLE.'.*', + UserModel::TABLE.'.username AS owner_username', + UserModel::TABLE.'.name AS owner_name', + "(SELECT count(*) FROM tasks WHERE tasks.project_id=projects.id AND tasks.is_active='1') AS nb_active_tasks" + ) ->eq(self::TABLE.'.id', $project_id) ->join(UserModel::TABLE, 'id', 'owner_id') ->join(TaskModel::TABLE, 'project_id', 'id') - ->groupBy(self::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name') ->findOne(); }