Fix count when there is a "group by" in the query (do not delete actual select).

This commit is contained in:
kj 2020-07-22 10:52:40 -04:00
parent a7cb44a04b
commit fe98d94692

View File

@ -25,7 +25,7 @@ class ModelMySQL {
static protected $tableSufix = 's';
static protected $db;
static protected $querySelect = [
'select' => '*',
'select' => ['*'],
'where' => '',
'from' => '',
'leftJoin' => '',
@ -83,7 +83,7 @@ class ModelMySQL {
*/
protected static function resetQuery() {
static::$querySelect = [
'select' => '*',
'select' => ['*'],
'where' => '',
'from' => '',
'leftJoin' => '',
@ -104,7 +104,7 @@ class ModelMySQL {
* Contiene la sentencia SQL.
*/
private static function buildQuery() {
$sql = 'SELECT '.static::$querySelect['select'];
$sql = 'SELECT '.join(', ', static::$querySelect['select']);
if (static::$querySelect['from'] != '') {
$sql .= ' FROM '.static::$querySelect['from'];
@ -302,7 +302,7 @@ class ModelMySQL {
$select[] = $db->real_escape_string($column);
}
static::$querySelect['select'] = join(', ', $select);
static::$querySelect['select'] = $select;
return new static();
}
@ -612,7 +612,10 @@ class ModelMySQL {
* @return int
*/
public static function count() {
static::$querySelect['select'] = 'count(*) as quantity';
if (static::$querySelect['select'] == ['*'])
static::$querySelect['select'] = ['count(*) as quantity'];
else
static::$querySelect['select'][] = 'count(*) as quantity';
$sql = static::buildQuery();
$result = static::query($sql)->fetch_assoc();
return $result['quantity'];