From b3ccaa8a8a5c1ce3336a6ee2d172729843adeeb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20Cuello=20Principal?= Date: Thu, 2 Jul 2026 23:59:53 +0200 Subject: [PATCH] Fix Legacy JoinModel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cualquier JoinModel legacy vuelve a funcionar con los filtros modernos del core 2026.4 que usan Where en vez de DataBaseWhere (SelectFilter, CheckboxFilter, DateFilter, NumberFilter, AutocompleteFilter, TreeFilter. Los métodos all, count, loadDataFromWhere y totalSum ahora aplican la clase Where que admite los dos tipos de filtros (where y databasewhere) --- Core/Model/Base/JoinModel.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Core/Model/Base/JoinModel.php b/Core/Model/Base/JoinModel.php index 8732084019..7b4f5823ce 100644 --- a/Core/Model/Base/JoinModel.php +++ b/Core/Model/Base/JoinModel.php @@ -22,6 +22,7 @@ use FacturaScripts\Core\Base\DataBase; use FacturaScripts\Core\Base\DataBase\DataBaseWhere; use FacturaScripts\Core\Cache; +use FacturaScripts\Core\Where; /** * @deprecated Usar FacturaScripts\Core\Template\JoinModel en su lugar. @@ -130,7 +131,7 @@ public function __set($name, $value) /** * Load data for the indicated where. * - * @param DataBaseWhere[] $where filters to apply to model records. + * @param DataBaseWhere[]|Where[] $where filters to apply to model records. * @param array $order fields to use in the sorting. For example ['code' => 'ASC'] * @param int $offset * @param int $limit @@ -142,7 +143,7 @@ public function all(array $where, array $order = [], int $offset = 0, int $limit $result = []; if ($this->checkTables()) { $sql = 'SELECT ' . $this->fieldsList() . ' FROM ' . $this->getSQLFrom() - . DataBaseWhere::getSQLWhere($where) . $this->getGroupBy() . $this->getOrderBy($order); + . Where::multiSqlLegacy($where) . $this->getGroupBy() . $this->getOrderBy($order); foreach (self::$dataBase->selectLimit($sql, $limit, $offset) as $row) { $result[] = new static($row); } @@ -164,7 +165,7 @@ public function clear() /** * Returns the number of records that meet the condition. * - * @param DataBaseWhere[] $where filters to apply to records. + * @param DataBaseWhere[]|Where[] $where filters to apply to records. * * @return int */ @@ -186,7 +187,7 @@ public function count(array $where = []): int $sql = 'SELECT ' . $groupFields . 'COUNT(*) count_total' . ' FROM ' . $this->getSQLFrom() - . DataBaseWhere::getSQLWhere($where) + . Where::multiSqlLegacy($where) . $this->getGroupBy(); $data = self::$dataBase->select($sql); @@ -285,7 +286,7 @@ public function loadFromCode($cod, array $where = [], array $orderby = []): bool $sql = 'SELECT ' . $this->fieldsList() . ' FROM ' . $this->getSQLFrom() - . DataBaseWhere::getSQLWhere($where) + . Where::multiSqlLegacy($where) . $this->getGroupBy() . $this->getOrderBy($orderby); @@ -330,8 +331,8 @@ public function totalSum(string $field, array $where = []): float $field = $fields[$field] ?? $field; $sql = false !== strpos($field, '(') ? - 'SELECT ' . $field . ' AS total_sum' . ' FROM ' . $this->getSQLFrom() . DataBaseWhere::getSQLWhere($where) : - 'SELECT SUM(' . $field . ') AS total_sum' . ' FROM ' . $this->getSQLFrom() . DataBaseWhere::getSQLWhere($where); + 'SELECT ' . $field . ' AS total_sum' . ' FROM ' . $this->getSQLFrom() . Where::multiSqlLegacy($where) : + 'SELECT SUM(' . $field . ') AS total_sum' . ' FROM ' . $this->getSQLFrom() . Where::multiSqlLegacy($where); $data = self::$dataBase->select($sql); $sum = count($data) == 1 ? (float)$data[0]['total_sum'] : 0.0;