Adding order by breaks grouped by query #6806

Open
opened 2026-01-22 15:39:07 +01:00 by admin · 3 comments
Owner

Originally created by @ghost on GitHub (Aug 16, 2021).

Hello!

I was trying to find a way to get entity result with relation count and I almost succeeded by following this post:

http://allan-simon.github.io/blog/posts/doctrine2-order-by-count-many-to-many/

The problem is that when I add order by, the query breaks and complains that some field is not in group by.

My doctrine/orm version is 2.8.1 and it seems it happened also on 2.9.3.

Is this a bug or am I missing something?

Originally created by @ghost on GitHub (Aug 16, 2021). Hello! I was trying to find a way to get entity result with relation count and I almost succeeded by following this post: http://allan-simon.github.io/blog/posts/doctrine2-order-by-count-many-to-many/ The problem is that when I add order by, the query breaks and complains that some field is not in group by. My doctrine/orm version is 2.8.1 and it seems it happened also on 2.9.3. Is this a bug or am I missing something?
Author
Owner

@greg0ire commented on GitHub (Aug 16, 2021):

I think you are missing something, but without the error message it will be hard to tell for sure.

@greg0ire commented on GitHub (Aug 16, 2021): I think you are missing something, but without the error message it will be hard to tell for sure.
Author
Owner

@ghost commented on GitHub (Aug 17, 2021):

@greg0ire This is the beginning of the error:
SQLSTATE[42000]: Syntax error or access violation: 1055 'mytable.r0_.id' isn't in GROUP BY" at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 128 {"exception":"#0 /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(182): Doctrine\\DBAL\\Driver\\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\\DBAL\\Driver\\PDO\\Exception))

I created simple test app here: https://github.com/mkoske/doctrine-test from the post I mentioned earlier and it seems to work just ok. I cannot get it to break. And yet, my code is almost same.

I investigated this and my code works as it should if I set fetchJoinCollection = false on paginator. But as soon as I set it to true, it breaks and I get this exception.

@ghost commented on GitHub (Aug 17, 2021): @greg0ire This is the beginning of the error: `SQLSTATE[42000]: Syntax error or access violation: 1055 'mytable.r0_.id' isn't in GROUP BY" at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 128 {"exception":"#0 /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(182): Doctrine\\DBAL\\Driver\\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\\DBAL\\Driver\\PDO\\Exception))` I created simple test app here: https://github.com/mkoske/doctrine-test from the post I mentioned earlier and it seems to work just ok. I cannot get it to break. And yet, my code is almost same. I investigated this and my code works as it should if I set `fetchJoinCollection = false` on paginator. But as soon as I set it to true, it breaks and I get this exception.
Author
Owner

@greg0ire commented on GitHub (Aug 17, 2021):

I investigated this and my code works as it should if I set fetchJoinCollection = false on paginator. But as soon as I set it to true, it breaks and I get this exception.

Ah so maybe you will be able to reproduce that in your test app?

@greg0ire commented on GitHub (Aug 17, 2021): > I investigated this and my code works as it should if I set fetchJoinCollection = false on paginator. But as soon as I set it to true, it breaks and I get this exception. Ah so maybe you will be able to reproduce that in your test app?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6806