We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When using multiple entity managers and database connections Bolt\Doctrine\Versions constructor throws error
Argument #2 ($tablePrefix) must be of type string, array given.
Bolt Version 5.1.4
To reproduce:
.env
DATABASE_URL=sqlite:///%kernel.project_dir%/var/data/bolt.sqlite DATABASE_URL2=sqlite:///%kernel.project_dir%/var/data/bolt2.sqlite
doctrine.yaml
doctrine: dbal: default_connection: default connections: default: charset: utf8mb4 url: '%env(resolve:DATABASE_URL)%' d2: charset: utf8mb4 url: '%env(resolve:DATABASE_URL2)%' # IMPORTANT: You MUST configure your server version, # either here or in the DATABASE_URL env var (see .env file) #server_version: '5.7' orm: auto_generate_proxy_classes: true entity_managers: default: naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware auto_mapping: true mappings: Bolt: is_bundle: false type: annotation dir: '%kernel.project_dir%/vendor/bolt/core/src/Entity' prefix: 'Bolt\Entity' alias: Bolt dql: string_functions: JSON_EXTRACT: Bolt\Doctrine\Functions\JsonExtract JSON_GET_TEXT: Scienta\DoctrineJsonFunctions\Query\AST\Functions\Postgresql\JsonGetText JSON_SEARCH: Scienta\DoctrineJsonFunctions\Query\AST\Functions\Mysql\JsonSearch CAST: Bolt\Doctrine\Query\Cast numeric_functions: RAND: Bolt\Doctrine\Functions\Rand d2: connection: d2 mappings: App: is_bundle: false type: annotation dir: '%kernel.project_dir%/src/Entity' prefix: 'App\Entity' alias: App
services.yaml
app.table_prefix: default: bolt_ d2: foo_ ... bind: $tablePrefix: '%app.table_prefix%'
The text was updated successfully, but these errors were encountered:
How I fixed it:
Version.php
public function __construct(Connection $connection, $tablePrefix = 'bolt') { $this->connection = $connection; $tablePrefix = is_array($tablePrefix) ? $tablePrefix['default'] : $tablePrefix; $this->tablePrefix = Str::ensureEndsWith($tablePrefix, '_'); }
TablePrefixTrait.php
protected function setTablePrefix(ObjectManager $manager, string $prefix) { $key = spl_object_hash($manager); $this->tablePrefixes[$key] = empty($prefix) ? $prefix : Str::ensureEndsWith($prefix, '_'); return $this; } ... protected function getTablePrefix(ObjectManager $manager): string { $key = spl_object_hash($manager); return $this->tablePrefixes[$key] ?? ''; }
TablePrefix.php
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void { $entityManager = $eventArgs->getEntityManager(); if ($tablePrefix = $this->getTablePrefix($entityManager)) { $classMetadata = $eventArgs->getClassMetadata(); ...
Sorry, something went wrong.
No branches or pull requests
When using multiple entity managers and database connections Bolt\Doctrine\Versions constructor throws error
Argument #2 ($tablePrefix) must be of type string, array given.
Bolt Version 5.1.4
To reproduce:
.env
doctrine.yaml
services.yaml
The text was updated successfully, but these errors were encountered: