diff --git a/include/class.client.php b/include/class.client.php index 31e185c8bef7c763731c6e492214e5522414ee75..50fda6cef195f8e01e9e4277ade1a5cc31f82d57 100644 --- a/include/class.client.php +++ b/include/class.client.php @@ -303,7 +303,8 @@ class EndUser extends BaseAuthenticatedUser { private function getStats() { $basic = Ticket::objects() ->annotate(array('count' => SqlAggregate::COUNT('ticket_id'))) - ->values('status__state', 'topic_id'); + ->values('status__state', 'topic_id') + ->distinct('status_id', 'topic_id'); // Share tickets among the organization for owners only $mine = clone $basic; diff --git a/include/class.orm.php b/include/class.orm.php index 72495a85a2b97db1c352bb993d51131953990b71..cac0eb39eab5a1c8e566314520d0ec5c0f2fa96a 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -2523,7 +2523,7 @@ class MySqlCompiler extends SqlCompiler { } // If there are annotations, add in these fields to the // GROUP BY clause - if ($queryset->annotations) + if ($queryset->annotations && !$queryset->distinct) $group_by[] = $unaliased; } } @@ -2557,7 +2557,7 @@ class MySqlCompiler extends SqlCompiler { } } // If no group by has been set yet, use the root model pk - if (!$group_by && !$queryset->aggregated) { + if (!$group_by && !$queryset->aggregated && !$queryset->distinct) { foreach ($model::getMeta('pk') as $pk) $group_by[] = $rootAlias .'.'. $pk; }