Skip to content

Invalid SQL generated by TranslationWalker when using LIMITΒ #2917

@xelax90

Description

@xelax90

Environment

Package

show

$ composer show --latest gedmo/doctrine-extensions
name     : gedmo/doctrine-extensions
descrip. : Doctrine behavioral extensions
keywords : Blameable, behaviors, doctrine, extensions, gedmo, loggable, nestedset, odm, orm, sluggable, sortable, timestampable, translatable, tree, uploadable
versions : * v3.18.0
latest   : v3.18.0
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : http://gediminasm.org/
source   : [git] https://github.com/doctrine-extensions/DoctrineExtensions.git 964db6c4fb5b0fc8aa25cc31b17471b4963460c6
dist     : [zip] https://api.github.com/repos/doctrine-extensions/DoctrineExtensions/zipball/964db6c4fb5b0fc8aa25cc31b17471b4963460c6 964db6c4fb5b0fc8aa25cc31b17471b4963460c6
path     : /git/httpdocs/vendor/gedmo/doctrine-extensions
names    : gedmo/doctrine-extensions

support
email : [email protected]
issues : https://github.com/doctrine-extensions/DoctrineExtensions/issues
source : https://github.com/doctrine-extensions/DoctrineExtensions/tree/v3.18.0
wiki : https://github.com/Atlantic18/DoctrineExtensions/tree/main/doc

autoload
psr-4
Gedmo\ => src/

requires
behat/transliterator ^1.2
doctrine/collections ^1.2 || ^2.0
doctrine/deprecations ^1.0
doctrine/event-manager ^1.2 || ^2.0
doctrine/persistence ^2.2 || ^3.0 || ^4.0
php ^7.4 || ^8.0
psr/cache ^1 || ^2 || ^3
psr/clock ^1
symfony/cache ^5.4 || ^6.0 || ^7.0

requires (dev)
doctrine/annotations ^1.13 || ^2.0
doctrine/cache ^1.11 || ^2.0
doctrine/common ^2.13 || ^3.0
doctrine/dbal ^3.7 || ^4.0
doctrine/doctrine-bundle ^2.3
doctrine/mongodb-odm ^2.3
doctrine/orm ^2.14.0 || ^3.0
friendsofphp/php-cs-fixer ^3.14.0
nesbot/carbon ^2.71 || ^3.0
phpstan/phpstan ^2.1.1
phpstan/phpstan-doctrine ^2.0.1
phpstan/phpstan-phpunit ^2.0.3
phpunit/phpunit ^9.6
rector/rector ^2.0.6
symfony/console ^5.4 || ^6.0 || ^7.0
symfony/doctrine-bridge ^5.4 || ^6.0 || ^7.0
symfony/phpunit-bridge ^6.0 || ^7.0
symfony/uid ^5.4 || ^6.0 || ^7.0
symfony/yaml ^5.4 || ^6.0 || ^7.0

suggests
doctrine/mongodb-odm to use the extensions with the MongoDB ODM
doctrine/orm to use the extensions with the ORM

conflicts
doctrine/annotations <1.13 || >=3.0
doctrine/common <2.13 || >=4.0
doctrine/dbal <3.7 || >=5.0
doctrine/mongodb-odm <2.3 || >=3.0
doctrine/orm <2.14.0 || 2.16.0 || 2.16.1 || >=4.0

Doctrine packages

show

$ composer show --latest 'doctrine/*'
doctrine/annotations               2.0.2  2.0.2  Docblock Annotations Parser
doctrine/cache                     2.2.0  2.2.0  PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.
doctrine/collections               2.2.2  2.2.2  PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common                    3.5.0  3.5.0  PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depend on such as better reflection support, p...
doctrine/dbal                      3.9.4  4.2.2  Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/deprecations              1.1.4  1.1.4  A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.
doctrine/doctrine-laminas-hydrator 3.6.1  3.6.1  Doctrine hydrators for Laminas applications
doctrine/doctrine-module           6.1.1  6.3.0  Laminas Module that provides Doctrine basic functionality required for ORM and ODM modules
doctrine/doctrine-orm-module       6.1.0  6.3.0  Laminas Module that provides Doctrine ORM functionality
doctrine/event-manager             1.2.0  2.0.1  The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.
doctrine/inflector                 2.0.10 2.0.10 PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.
doctrine/instantiator              2.0.0  2.0.0  A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                     2.1.1  3.0.1  PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                3.8.2  3.8.2  PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easi...
doctrine/orm                       2.20.1 3.3.1  Object-Relational-Mapper for PHP
doctrine/persistence               3.4.0  4.0.0  The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.

PHP version

$ php -v
PHP 8.1.25 (cli) (built: Nov 17 2023 14:15:02) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.25, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.25, Copyright (c), by Zend Technologies
    with Xdebug v3.2.2, Copyright (c) 2002-2023, by Derick Rethan

Subject

In version 3.18.0 an extra LIMIT clause is appended to SQL statements after the TranslationWalker. This does not happen in 3.17.1.

Steps to reproduce

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query;
use Gedmo\Translatable\Query\TreeWalker\TranslationWalker;
use Gedmo\Translatable\TranslatableListener;
use MyProject\Entity\SystemOption;

$query = $this->entityManager->createQueryBuilder()
    ->select('s.title')
    ->from(SystemOption::class, 's')
    ->setMaxResults(10)
    ->getQuery();
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, TranslationWalker::class);
$query->setHint(TranslatableListener::HINT_TRANSLATABLE_LOCALE, 'de_DE');
$query->setHint(TranslatableListener::HINT_FALLBACK, 1);
dump($query->getSQL());

Expected results

SELECT COALESCE(t1_.content, s0_.title) AS title_0
FROM SystemOption s0_
LEFT JOIN Translation t1_ ON t1_.locale = 'de_DE'
    AND t1_.field = 'title'
    AND t1_.objectClass = 'MyProject\\Entity\\SystemOption'
    AND t1_.foreignKey = s0_.id
LEFT JOIN Translation t2_ ON t2_.locale = 'de_DE'
    AND t2_.field = 'description'
    AND t2_.objectClass = 'MyProject\\Entity\\SystemOption'
    AND t2_.foreignKey = s0_.id
LIMIT 10

Actual results

SELECT COALESCE(t1_.content, s0_.title) AS title_0
FROM SystemOption s0_
LEFT JOIN Translation t1_ ON t1_.locale = 'de_DE'
    AND t1_.field = 'title'
    AND t1_.objectClass = 'MyProject\\Entity\\SystemOption'
    AND t1_.foreignKey = s0_.id
LEFT JOIN Translation t2_ ON t2_.locale = 'de_DE'
    AND t2_.field = 'description'
    AND t2_.objectClass = 'MyProject\\Entity\\SystemOption'
    AND t2_.foreignKey = s0_.id
LIMIT 10
LIMIT 10

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions