Skip to content

Commit 5d8ee39

Browse files
committed
fix count query
1 parent 07d1838 commit 5d8ee39

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/Model/AggregateModel.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,16 @@ public function action(string $mode, array $args = [])
153153

154154
return $query;
155155
case 'count':
156-
$query = parent::action($mode, $args);
157-
if (isset($query->args['where'])) {
158-
$query->args['having'] = $query->args['where'];
159-
unset($query->args['where']);
160-
}
156+
$innerQuery = $this->action('select');
157+
$innerQuery->reset('field')->field($this->expr('1'));
161158

162-
$query->reset('field')->field($this->expr('1'));
163-
$this->initQueryGrouping($query);
159+
$query = $innerQuery->dsql()
160+
->field('count(*)', $args['alias'] ?? null)
161+
->table($this->expr('([]) {}', [$innerQuery, '_tc']));
164162

165163
$this->hook(self::HOOK_INIT_SELECT_QUERY, [$query]);
166164

167-
return $query->dsql()->field('count(*)')->table($this->expr('([]) {}', [$query, '_tc']));
165+
return $query;
168166
// case 'field':
169167
// case 'fx':
170168
// case 'fx0':

0 commit comments

Comments
 (0)