|
|
@ -62,11 +62,11 @@ class SqlCriteria |
|
|
|
return $this->model->find($this->select, $this->distinct, $this->where, $this->order, $this->limit, null, $this->group_by, $this->sql_expression, $this->sql_expression_params); |
|
|
|
} |
|
|
|
|
|
|
|
private function defineJoinExpressions() |
|
|
|
private function defineJoinExpressions($select = null) |
|
|
|
{ |
|
|
|
if ($this->sql_join_expressions) { |
|
|
|
if (!$this->sql_expression) { |
|
|
|
$select = $this->model->getDb()->selectExpr($this->select, $this->distinct); |
|
|
|
$select = $this->model->getDb()->selectExpr($select ? : $this->select, $this->distinct); |
|
|
|
$this->sql_expression = 'SELECT ' . $select . ' FROM :table'; |
|
|
|
} |
|
|
|
$this->sql_expression .= ' ' . implode(' ', $this->sql_join_expressions); |
|
|
@ -81,13 +81,13 @@ class SqlCriteria |
|
|
|
|
|
|
|
public function count($select = 'x') |
|
|
|
{ |
|
|
|
$this->defineJoinExpressions(); |
|
|
|
$this->defineJoinExpressions($select); |
|
|
|
$sql_expression_backup = $this->sql_expression; |
|
|
|
if ($select) { |
|
|
|
$this->select( $select ); |
|
|
|
} |
|
|
|
if (!$this->sql_expression) { |
|
|
|
$this->sql_expression = 'SELECT COUNT(*) as count FROM :table'; |
|
|
|
$this->sql_expression = 'SELECT COUNT(' . ($select ? $select : '*') . ') as count FROM :table'; |
|
|
|
} |
|
|
|
$count = $this->model->count($select, '', $this->where, null, $this->group_by, $this->sql_expression, $this->sql_expression_params)->fetchField('count'); |
|
|
|
$this->sql_expression = $sql_expression_backup; |
|
|
|