diff --git a/src/Doctrine/TablePrefix.php b/src/Doctrine/TablePrefix.php index 41b56c603..3e3cae7ce 100644 --- a/src/Doctrine/TablePrefix.php +++ b/src/Doctrine/TablePrefix.php @@ -19,7 +19,8 @@ public function __construct($tablePrefix, ManagerRegistry $managerRegistry) public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void { - if ($tablePrefix = $this->getTablePrefix()) { + $entityManager = $eventArgs->getEntityManager(); + if ($tablePrefix = $this->getTablePrefix($entityManager)) { $classMetadata = $eventArgs->getClassMetadata(); if (! $classMetadata->isInheritanceTypeSingleTable() diff --git a/src/Doctrine/TablePrefixTrait.php b/src/Doctrine/TablePrefixTrait.php index ae49fb4c2..ccf34299e 100644 --- a/src/Doctrine/TablePrefixTrait.php +++ b/src/Doctrine/TablePrefixTrait.php @@ -24,7 +24,7 @@ trait TablePrefixTrait protected function setTablePrefix(ObjectManager $manager, string $prefix) { $key = spl_object_hash($manager); - $this->tablePrefixes[$key] = Str::ensureEndsWith($prefix, '_'); + $this->tablePrefixes[$key] = empty($prefix) ? '' : Str::ensureEndsWith($prefix, '_'); return $this; } @@ -46,14 +46,10 @@ protected function setTablePrefixes($tablePrefixes, ManagerRegistry $managerRegi return $this; } - /** - * Since we introduced `symfony/proxy-manager-bridge`, the keys in the tableprefix - * no longer match what the manager tells us it should be. For example, the - * given key was `0000000005ee10ad0000000043b453e3`, but in our reference - * table we had `0000000005ee10e90000000043b453e3`. We just return the first one, now - */ - protected function getTablePrefix(): string + protected function getTablePrefix(ObjectManager $manager): string { - return current($this->tablePrefixes); + $key = spl_object_hash($manager); + + return $this->tablePrefixes[$key] ?? ''; } } diff --git a/src/Doctrine/Version.php b/src/Doctrine/Version.php index e32303d86..91d111037 100644 --- a/src/Doctrine/Version.php +++ b/src/Doctrine/Version.php @@ -20,9 +20,10 @@ class Version /** @var string */ private $tablePrefix; - public function __construct(Connection $connection, string $tablePrefix = 'bolt') + public function __construct(Connection $connection, $tablePrefix = 'bolt') { $this->connection = $connection; + $tablePrefix = is_array($tablePrefix) ? $tablePrefix['default'] : $tablePrefix; $this->tablePrefix = Str::ensureEndsWith($tablePrefix, '_'); }