@@ -89,11 +89,15 @@ class ProjectModel extends Base
|
|||||||
public function getByIdWithOwnerAndTaskCount($project_id)
|
public function getByIdWithOwnerAndTaskCount($project_id)
|
||||||
{
|
{
|
||||||
return $this->db->table(self::TABLE)
|
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)
|
->eq(self::TABLE.'.id', $project_id)
|
||||||
->join(UserModel::TABLE, 'id', 'owner_id')
|
->join(UserModel::TABLE, 'id', 'owner_id')
|
||||||
->join(TaskModel::TABLE, 'project_id', 'id')
|
->join(TaskModel::TABLE, 'project_id', 'id')
|
||||||
->groupBy(self::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name')
|
|
||||||
->findOne();
|
->findOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user