From b8b1a1c8f91c92a80b6fde92566463d61ac32d09 Mon Sep 17 00:00:00 2001 From: kj Date: Sat, 11 Sep 2021 20:02:23 -0400 Subject: [PATCH] Enable to use limit funtion on count function instead send limit directly. --- src/Libs/ModelMySQL.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Libs/ModelMySQL.php b/src/Libs/ModelMySQL.php index 5f24986..82576fd 100644 --- a/src/Libs/ModelMySQL.php +++ b/src/Libs/ModelMySQL.php @@ -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';