We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon 2.0 PHQL Distinct

Hey,

I was checking out 2.0 and one of my PHQL queres uses distinct. It works fine in 1.3.4 but omits the column in 2.0. I was wondering if anybody knows if this is known issue or if there is newer syntax for using distinct in PHQL?

2.0 is supposed to have 100% feature parity with the 1.x branch. If you can distill this down to a simple example case, it would make a good bug report.

Essentially a statement such as:

SELECT DISTINCT value FROM model JOIN etc.

This won't return "value" in 2.0 but returns fine in 1.3.4 when using PHQL.

Alex, did you find a solution? I think I might have a similar situation here:

$query = $this->modelsManager->createQuery('SELECT DISTINCT id, name FROM App\Models\Brands');
$result = $query->execute();

Dumping the returned result shows the following. It seems that the first column is returned as "_0", regardless of the column. (Switching the order of name and id still returned the first column as "_0".

[_pdoStatement:protected] => PDOStatement Object
(
[queryString] => SELECT DISTINCT brands.id AS _0, brands.name AS name FROM brands
)
[_sqlStatement:protected] => SELECT DISTINCT brands.id AS _0, brands.name AS name FROM brands