Browse Source

Merge branch 'namespace' of dimti.ru:majestic into namespace

namespace
Alexander Demidov 11 years ago
parent
commit
37c6dab160
  1. 12
      Model/SqlCriteria.php

12
Model/SqlCriteria.php

@ -70,6 +70,7 @@ class SqlCriteria
$this->sql_expression = 'SELECT ' . $select . ' FROM :table'; $this->sql_expression = 'SELECT ' . $select . ' FROM :table';
} }
$this->sql_expression .= ' ' . implode(' ', $this->sql_join_expressions); $this->sql_expression .= ' ' . implode(' ', $this->sql_join_expressions);
$this->sql_join_expressions = null;
} }
} }
@ -80,13 +81,16 @@ class SqlCriteria
public function count() public function count()
{ {
if ($this->sql_expression && strpos($this->sql_expression, 'COUNT(*) as count')) {
;
$this->defineJoinExpressions();
$sql_expression_backup = $this->sql_expression;
if ($this->sql_expression && !strstr('COUNT(*)', $this->sql_expression)) {
$this->sql_expression = preg_replace('#^SELECT .+ FROM#', 'SELECT COUNT(*) as count FROM', $this->sql_expression);
} else { } else {
$this->sql_expression = 'SELECT COUNT(*) as count FROM :table'; $this->sql_expression = 'SELECT COUNT(*) as count FROM :table';
} }
$this->defineJoinExpressions();
return $this->model->find(array(), '', $this->where, null, null, null, null, $this->sql_expression, $this->sql_expression_params)->fetchField('count');
$count = $this->model->find(array(), '', $this->where, null, null, null, null, $this->sql_expression, $this->sql_expression_params)->fetchField('count');
$this->sql_expression = $sql_expression_backup;
return $count;
} }
private function defineJoinTablePlaceholder($table_name) private function defineJoinTablePlaceholder($table_name)

Loading…
Cancel
Save