Compare commits

..

2 Commits

Author SHA1 Message Date
kj
405cf1cb34 Fix count on not resetQuery. 2021-08-14 17:46:14 -04:00
kj
8069fb28a1 Ignore orderby on count. 2021-08-14 17:45:23 -04:00

View File

@ -631,10 +631,28 @@ class ModelMySQL {
* @return int * @return int
*/ */
public static function count($resetQuery = true) { public static function count($resetQuery = true) {
if (!$resetQuery)
$backup = [
'select' => static::$querySelect['select'],
'sql_calc_found_rows' => static::$querySelect['sql_calc_found_rows'],
'limit' => static::$querySelect['limit'],
'orderBy' => static::$querySelect['orderBy']
];
static::$querySelect['select'] = ['1']; static::$querySelect['select'] = ['1'];
static::$querySelect['sql_calc_found_rows'] = true; static::$querySelect['sql_calc_found_rows'] = true;
static::$querySelect['limit'] = '1'; static::$querySelect['limit'] = '1';
static::$querySelect['orderBy'] = '';
$sql = static::buildQuery($resetQuery); $sql = static::buildQuery($resetQuery);
if (!$resetQuery) {
static::$querySelect['select'] = $backup['select'];
static::$querySelect['sql_calc_found_rows'] = $backup['sql_calc_found_rows'];
static::$querySelect['limit'] = $backup['limit'];
static::$querySelect['orderBy'] = $backup['orderBy'];
}
$result = static::query($sql)->fetch_assoc(); $result = static::query($sql)->fetch_assoc();
return static::found_row(); return static::found_row();
} }