Fix regression with MySQL

Fixes #4430 and #4431
This commit is contained in:
Frédéric Guillot 2020-03-04 20:35:10 -08:00
parent 5e7758d39d
commit 9ebec002cd
1 changed files with 6 additions and 2 deletions

View File

@ -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();
}