Enable to use limit funtion on count function instead send limit directly.

This commit is contained in:
kj 2021-09-11 20:02:23 -04:00
parent 182635bc9c
commit b8b1a1c8f9
1 changed files with 4 additions and 5 deletions

View File

@ -628,12 +628,12 @@ class ModelMySQL {
* @param boolean $resetQuery
* Indica si el query debe reiniciarse o no (por defecto es true).
*
* @param int $límite
* Establece un límite máximo a contar (útil en caso de querer optimizar en tablas muy extensas).
* @param boolean $useLimit
* Permite usar limit para estabecer un máximo inical y final para contar. Requiere que se haya definido antes el límite.
*
* @return int
*/
public static function count($resetQuery = true, $limit = null) {
public static function count($resetQuery = true, $useLimit = false) {
if (!$resetQuery)
$backup = [
'select' => static::$querySelect['select'],
@ -642,10 +642,9 @@ class ModelMySQL {
'orderBy' => static::$querySelect['orderBy']
];
if (is_numeric($limit)) {
if ($useLimit && static::$querySelect['limit'] != '') {
static::$querySelect['select'] = ['1'];
static::$querySelect['sql_calc_found_rows'] = false;
static::$querySelect['limit'] = $limit;
static::$querySelect['orderBy'] = '';
$sql = 'SELECT COUNT(1) AS quantity FROM ('.static::buildQuery($resetQuery).') AS counted';