Fix count on not resetQuery.

This commit is contained in:
kj 2021-08-14 17:46:14 -04:00
parent 8069fb28a1
commit 405cf1cb34

View File

@ -631,11 +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'] = ''; 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();
} }