BaseType/Fixup

* fix totals query. Rather treat original query as subquery than trying to modify it
 * fixes queries utilizing HAVING and GROUP BY
This commit is contained in:
Sarjuuk
2024-08-27 17:06:55 +02:00
parent af303f447a
commit 778c21e817

View File

@@ -277,8 +277,13 @@ abstract class BaseType
{ {
if ($calcTotal) if ($calcTotal)
{ {
$totalQuery = substr_replace($totalQuery, 'SELECT COUNT(*) ', 0, strpos($totalQuery, 'FROM')); // hackfix the inner items query to not contain duplicate column names
$this->matches += DB::{$n}($dbIdx)->selectCell($totalQuery); // yes i know the real solution would be to not have items and item_stats share column names
// soon™....
if (get_class($this) == 'ItemList')
$totalQuery = str_replace([', `is`.*', ', i.id AS id'], '', $totalQuery);
$this->matches += DB::{$n}($dbIdx)->selectCell('SELECT COUNT(*) FROM ('.$totalQuery.') x');
} }
foreach ($rows as $id => $row) foreach ($rows as $id => $row)