doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.9k stars 2.5k forks source link

$qb->expr()->countDistinct() fails with multiple values #5544

Open greeny opened 8 years ago

greeny commented 8 years ago

I have $qb (QueryBuilder), and i call this:

$qb->expr()->countDistinct('e.name', 'e.value')

Generated SQL / DQL is valid, but Parser complains about syntax error:

Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got ','

In tests, there is a test for multiple arguments in countDistinct(), but no test for Parser accepting multiple arguments for COUNT(DISTINCT

oskargunther commented 6 years ago

Still not solved? Any work around?

lart2150 commented 6 years ago

I found a major hack of a workaround. If you combine the two fields and then select distinct of the two it works. COUNT(DISTINCT CONCAT(ps.date, s.id))

lcobucci commented 6 years ago

It would be amazing if someone could send us a failing test case that reproduces that behaviour. It would help us a lot to identify and fix the issue you're describing.

You can find examples on https://github.com/doctrine/doctrine2/tree/388afb46d0cb3ed0c51332e8df0de9e942c2690b/tests/Doctrine/Tests/ORM/Functional/Ticket