Skip to content

[TreeClosure] Entities on custom database schema not supported #3006

@pchabbert

Description

@pchabbert

Environment

PhP 8.2 with Symfony 7.3 and PostgresSQL 15

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.21.0
released : 2025-09-22, 1 month ago
latest   : v3.21.0 released 2025-09-22, 1 month ago
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 eb53dfcb2b592327b76ac5226fbb003d32aea37e
dist     : [zip] https://api.github.com/repos/doctrine-extensions/DoctrineExtensions/zipball/eb53dfcb2b592327b76ac5226fbb003d32aea37e eb53dfcb2b592327b76ac5226fbb003d32aea37e
path     : /var/www/symfony/vendor/gedmo/doctrine-extensions
names    : gedmo/doctrine-extensions

support
docs : https://github.com/doctrine-extensions/DoctrineExtensions/tree/main/doc
issues : https://github.com/doctrine-extensions/DoctrineExtensions/issues
source : https://github.com/doctrine-extensions/DoctrineExtensions/tree/v3.21.0

autoload
psr-4
Gedmo\ => src/

requires
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
symfony/string ^5.4 || ^6.0 || ^7.0

requires (dev)
behat/transliterator ^1.2
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.20 || ^3.3
friendsofphp/php-cs-fixer ^3.70
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.4 || ^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
behat/transliterator <1.2 || >=2.0
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.20 || >=3.0 <3.3 || >=4.0

Doctrine packages

show

$ composer show --latest 'doctrine/*'
Color legend:
- patch or minor release available - update recommended
- major release available - update possible
- up to date version

Direct dependencies required in composer.json:
doctrine/dbal                       3.10.3 4.3.4  Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/doctrine-bundle            2.18.0 2.18.0 Symfony DoctrineBundle
doctrine/doctrine-fixtures-bundle   3.7.2  4.3.0  Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle 3.5.0  3.5.0  Symfony DoctrineMigrationsBundle
doctrine/orm                        3.5.3  3.5.3  Object-Relational-Mapper for PHP

Transitive dependencies not required in composer.json:
doctrine/annotations                2.0.2  2.0.2  Docblock Annotations Parser
Package doctrine/annotations is abandoned, you should avoid using it. No replacement was suggested.
doctrine/collections                2.4.0  2.4.0  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, proxies and much more.
doctrine/data-fixtures              2.2.0  2.2.0  Data Fixtures for all Doctrine Object Managers
doctrine/deprecations               1.1.5  1.1.5  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/event-manager              2.0.1  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.1.0  2.1.0  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                      3.0.1  3.0.1  PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                 3.9.4  3.9.4  PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a very easy to use and a powerful tool.
doctrine/persistence                3.4.3  4.1.1  The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.
doctrine/sql-formatter              1.5.3  1.5.3  a PHP SQL highlighting library

PHP version

$ php -v
PHP 8.2.29 (cli) (built: Sep  8 2025 21:24:09) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.29, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.29, Copyright (c), by Zend Technologies
    with Xdebug v3.4.5, Copyright (c) 2002-2025, by Derick Rethans

Subject

Using Tree and TreeClosure with entities using a specific postgres sql schema does not work.

Tree\Strategy\ORM\Closure::processPostPersist does not seem to care about table schema

Steps to reproduce

With this minimal entites

<?php

namespace App\Entity\Comment;

use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;


#[ORM\Entity(repositoryClass: CommentRepository::class)]
#[ORM\Table(name: 'comment_comment', schema:'private')]
#[Gedmo\Tree(type: 'closure')]
#[Gedmo\TreeClosure(class: CommentClosure::class)]
class Comment
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    public $id;

    #[ORM\ManyToOne(targetEntity: self::class)]
    #[ORM\JoinColumn(nullable: true, onDelete: 'CASCADE')]
    #[Gedmo\TreeParent]
    protected ?Comment $parent;
}
<?php

namespace App\Entity\Comment;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'comment_comment_closure', schema: 'private')]
#[ORM\UniqueConstraint(name: 'closure_unique_idx', columns: ['ancestor', 'descendant'])]
#[ORM\Index(name: 'closure_depth_idx', columns: ['depth'])]
class CommentClosure
{
    #[ORM\ManyToOne(targetEntity: Comment::class, inversedBy: 'descendants', fetch: 'LAZY')]
    #[ORM\JoinColumn(name: 'ancestor', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
    public $ancestor;

    #[ORM\ManyToOne(targetEntity: Comment::class, inversedBy: 'ancestors', fetch: 'LAZY')]
    #[ORM\JoinColumn(name: 'descendant', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
    public $descendant;
}

Then try to persist/flush a new Comment

$comment = (new Comment());
$this->entityManager->persist($comment);
$this->entityManager->flush();

Expected results

Comment will be saved correctly in database without any exceptions.

Actual results

On persist then flush a Comment an SQL exception has been throwed : undefined table comment_comment_closure

Doctrine\DBAL\Exception\TableNotFoundException:
An exception occurred while executing a query: SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "comment_comment_closure" does not exist
LINE 1: INSERT INTO comment_comment_closure (ancestor, descend...
                    ^

  at vendor/doctrine/dbal/src/Driver/API/PostgreSQL/ExceptionConverter.php:71
  at Doctrine\DBAL\Driver\API\PostgreSQL\ExceptionConverter->convert(object(Exception), object(Query))
     (vendor/doctrine/dbal/src/Connection.php:1976)
  at Doctrine\DBAL\Connection->handleDriverException(object(Exception), object(Query))
     (vendor/doctrine/dbal/src/Connection.php:1918)
  at Doctrine\DBAL\Connection->convertExceptionDuringQuery(object(Exception), 'INSERT INTO comment_comment_closure (ancestor, descendant, depth) VALUES (?, ?, ?)', array(2, 2, 0), array())
     (vendor/doctrine/dbal/src/Connection.php:1218)
  at Doctrine\DBAL\Connection->executeStatement('INSERT INTO comment_comment_closure (ancestor, descendant, depth) VALUES (?, ?, ?)', array(2, 2, 0), array())
     (vendor/doctrine/dbal/src/Connection.php:814)
  at Doctrine\DBAL\Connection->insert('comment_comment_closure', array('ancestor' => 2, 'descendant' => 2, 'depth' => 0))
     (vendor/gedmo/doctrine-extensions/src/Tree/Strategy/ORM/Closure.php:373)
  at Gedmo\Tree\Strategy\ORM\Closure->processPostPersist(object(EntityManagerGhostAe7f1a2), object(Comment), object(ORM))
     (vendor/gedmo/doctrine-extensions/src/Tree/TreeListener.php:267)
  at Gedmo\Tree\TreeListener->postPersist(object(PostPersistEventArgs))
     (vendor/symfony/doctrine-bridge/ContainerAwareEventManager.php:56)
  at Symfony\Bridge\Doctrine\ContainerAwareEventManager->dispatchEvent('postPersist', object(PostPersistEventArgs))
     (vendor/doctrine/orm/src/Event/ListenersInvoker.php:95)
  at Doctrine\ORM\Event\ListenersInvoker->invoke(object(ClassMetadata), 'postPersist', object(Comment), object(PostPersistEventArgs), 4)
     (vendor/doctrine/orm/src/UnitOfWork.php:1079)
  at Doctrine\ORM\UnitOfWork->executeInserts()
     (vendor/doctrine/orm/src/UnitOfWork.php:402)
  at Doctrine\ORM\UnitOfWork->commit()
     (vendor/doctrine/orm/src/EntityManager.php:268)
  at Doctrine\ORM\EntityManager->flush()
[...]
     (vendor/symfony/http-kernel/HttpKernel.php:183)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:76)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:182)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     (vendor/autoload_runtime.php:29)
  at require_once('/var/www/symfony/vendor/autoload_runtime.php')
     (public/index.php:5)                

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions