|
|
@ -70,6 +70,7 @@ class SqlCriteria |
|
|
|
$this->sql_expression = 'SELECT ' . $select . ' FROM :table'; |
|
|
|
} |
|
|
|
$this->sql_expression .= ' ' . implode(' ', $this->sql_join_expressions); |
|
|
|
$this->sql_join_expressions = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -80,13 +81,16 @@ class SqlCriteria |
|
|
|
|
|
|
|
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 { |
|
|
|
$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) |
|
|
|