Enable to use limit funtion on count function instead send limit directly.
This commit is contained in:
parent
182635bc9c
commit
b8b1a1c8f9
@ -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';
|
||||
|
Loading…
Reference in New Issue
Block a user