Browse Source

Correct count in SqlCriteria

namespace
Alexander Demidov 10 years ago
parent
commit
388673d856
  1. 2
      Model/SqlCriteria.php

2
Model/SqlCriteria.php

@ -88,6 +88,8 @@ class SqlCriteria
if (!$this->sql_expression) { if (!$this->sql_expression) {
$this->sql_expression = 'SELECT COUNT(' . ($select ? $select : '*') . ') as count FROM :table'; $this->sql_expression = 'SELECT COUNT(' . ($select ? $select : '*') . ') as count FROM :table';
$select_parent_query = 'x.count'; $select_parent_query = 'x.count';
} else {
$this->sql_expression = preg_replace('#SELECT.+FROM#', 'SELECT COUNT(' . ($select ? $select : '*') . ') as count FROM', $this->sql_expression);
} }
$count = $this->model->count($select_parent_query, $this->where, null, $this->group_by, $this->sql_expression, $this->sql_expression_params)->fetchField('count'); $count = $this->model->count($select_parent_query, $this->where, null, $this->group_by, $this->sql_expression, $this->sql_expression_params)->fetchField('count');
$this->sql_expression = $sql_expression_backup; $this->sql_expression = $sql_expression_backup;

Loading…
Cancel
Save