Describe the bug
Phalcon Query Builder checks if the (full) group by syntax exists in the model, while it should only check the column name or perhaps skip the check entirely. In MySQL you can specify the alias for the group by clause as specify in the column select, for Postgres this isn't allowed.
To Reproduce
Steps to reproduce the behavior:
Consider following model:
use Phalcon\Mvc\Model;
final class InvoiceStatistic extends Model
{
protected string $invoiceDate;
protected int $count;
protected int $countryId;
/**
* Init
*/
public function initialize(): void
{
parent::setSource('invoice_statistic');
}
/**
* Column map
*/
public function columnMap(): array
{
return [
'invoice_date' => 'invoiceDate',
'count' => 'count',
'country_id' => 'countryId',
];
}
}
Create table syntax:
CREATE TABLE "invoice_statistic" (
"invoice_date" TIMESTAMP NOT NULL,
"count" int8 NOT NULL,
"country_id" int2 NOT NULL,
);
Fatal error: Uncaught Phalcon\Mvc\Model\Exception: Column 'DATE_PART('year', invoiceDate)' doesn't belong to any of the selected models (1), when preparing: SELECT DATE_PART('year', invoiceDate) year, countryId, SUM(count) count FROM [InvoiceStatistic] GROUP BY [DATE_PART('year', invoiceDate)], [countryId] in /www/public/index.php:61
Describe the bug Phalcon Query Builder checks if the (full) group by syntax exists in the model, while it should only check the column name or perhaps skip the check entirely. In MySQL you can specify the alias for the group by clause as specify in the column select, for Postgres this isn't allowed.
To Reproduce Steps to reproduce the behavior:
Consider following model:
Create table syntax:
Executing code:
Throws the following exception:
Expected behavior No error, group by should work as expected. Error caused by Exception at: https://github.com/phalcon/cphalcon/blob/v5.7.0/phalcon/Mvc/Model/Query.zep#L3025
Details
php --ri phalcon
)5.6.2
(also applicable in5.7.0
)8.3
Alpine Linux 3.19
Compiling from source
0.17.0
Apache / PHP-FPM
Postgres 16.1