Uncategorized

Disable ONLY_FULL_GROUP_BY in doctrine

Anxious from getting an exception of ONLY_FULL_GROUP_BY with the Symfony project?

[2021-06-11T21:17:30.912452+03:00] request.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\Exception\DriverException: "An exception occurred while executing ... which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by at /var/www/project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:112)"} []

There is a best and simple solution if you want to get rid of this exception from a particular Symfony project, all you need to do is, you have to update the configuration of the doctrine.

You need to add 1002 key inside the options key with the value ‘SET sql_mode=(SELECT REPLACE(@@sql_mode, “ONLY_FULL_GROUP_BY”, “”))’ under the dbal configuration.
Like this:-

doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'

        options:
            1002: 'SET sql_mode=(SELECT REPLACE(@@sql_mode, "ONLY_FULL_GROUP_BY", ""))'

        # ...

That’s it. Now clear the cache if you’re having any trouble otherwise you’re ready to go.

That’s how you could disable ONLY_FULL_GROUP_BY in doctrine.