mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
make count behave like in SQL
also fixed count behavior according to limit and offset. fixes #1458
This commit is contained in:
@ -283,13 +283,7 @@ class Query extends Component implements QueryInterface
|
||||
|
||||
$options = [];
|
||||
$options['search_type'] = 'count';
|
||||
$count = $this->createCommand($db)->search($options)['hits']['total'];
|
||||
if ($this->limit === null && $this->offset === null) {
|
||||
return $count;
|
||||
} elseif ($this->offset !== null) {
|
||||
$count = $this->offset < $count ? $count - $this->offset : 0;
|
||||
}
|
||||
return $this->limit === null ? $count : ($this->limit > $count ? $count : $this->limit);
|
||||
return $this->createCommand($db)->search($options)['hits']['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user