Fix resetQuery.

This commit is contained in:
kj 2022-07-29 22:23:07 -04:00
parent 2c7938a0c3
commit 8d47e10d7a

View File

@ -154,13 +154,10 @@ class Model {
* Construye la sentencia SQL a partir static::$querySelect y una vez
* construída, llama a resetQuery.
*
* @param bool $resetQuery
* Indica si el query debe reiniciarse o no (por defecto es true).
*
* @return string
* Contiene la sentencia SQL.
*/
protected static function buildQuery(bool $resetQuery = true) : string {
protected static function buildQuery() : string {
$sql = 'SELECT '.join(', ', static::$querySelect['select']);
if (static::$querySelect['from'] != '') {
@ -681,16 +678,16 @@ class Model {
static::$querySelect['select'] = ['1'];
static::$querySelect['orderBy'] = '';
$sql = 'SELECT COUNT(1) AS quantity FROM ('.static::buildQuery($resetQuery).') AS counted';
$queryResult = static::query($sql);
$sql = 'SELECT COUNT(1) AS quantity FROM ('.static::buildQuery().') AS counted';
$queryResult = static::query($sql, $resetQuery);
$result = $queryResult[0]['quantity'];
} else {
static::$querySelect['select'] = ["COUNT(".static::$primaryKey.") as quantity"];
static::$querySelect['limit'] = '1';
static::$querySelect['orderBy'] = '';
$sql = static::buildQuery($resetQuery);
$queryResult = static::query($sql);
$sql = static::buildQuery();
$queryResult = static::query($sql, $resetQuery);
$result = $queryResult[0]['quantity'];
}
@ -758,8 +755,8 @@ class Model {
* Contiene un arreglo de instancias de la clase actual.
*/
public static function get(bool $resetQuery = true) : array { // Devuelve array vacío si no encuentra nada.
$sql = static::buildQuery($resetQuery);
$result = static::query($sql);
$sql = static::buildQuery();
$result = static::query($sql, $resetQuery);
$instances = [];