Skip to content

[Doctrine] Cleaning up the config code samples #17755

New issue

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

Merged
merged 1 commit into from
Feb 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 16 additions & 41 deletions doctrine/multiple_entity_managers.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. index::
single: Doctrine; Multiple entity managers

How to Work with multiple Entity Managers and Connections
How to Work with Multiple Entity Managers and Connections
=========================================================

You can use multiple Doctrine entity managers or connections in a Symfony
Expand Down Expand Up @@ -32,20 +32,12 @@ The following configuration code shows how you can configure two entity managers
# config/packages/doctrine.yaml
doctrine:
dbal:
default_connection: default
connections:
default:
# configure these for your database server
url: '%env(resolve:DATABASE_URL)%'
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
customer:
# configure these for your database server
url: '%env(resolve:DATABASE_CUSTOMER_URL)%'
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
url: '%env(resolve:CUSTOMER_DATABASE_URL)%'
default_connection: default
orm:
default_entity_manager: default
entity_managers:
Expand Down Expand Up @@ -82,20 +74,12 @@ The following configuration code shows how you can configure two entity managers

<doctrine:config>
<doctrine:dbal default-connection="default">
<!-- configure these for your database server -->
<doctrine:connection name="default"
url="%env(resolve:DATABASE_URL)%"
driver="pdo_mysql"
server_version="5.7"
charset="utf8mb4"
/>

<!-- configure these for your database server -->
<doctrine:connection name="customer"
url="%env(resolve:DATABASE_CUSTOMER_URL)%"
driver="pdo_mysql"
server_version="5.7"
charset="utf8mb4"
url="%env(resolve:CUSTOMER_DATABASE_URL)%"
/>
</doctrine:dbal>

Expand Down Expand Up @@ -131,37 +115,28 @@ The following configuration code shows how you can configure two entity managers
use Symfony\Config\DoctrineConfig;

return static function (DoctrineConfig $doctrine) {
$doctrine->dbal()->defaultConnection('default');

// configure these for your database server
// Connections:
$doctrine->dbal()
->connection('default')
->url(env('DATABASE_URL')->resolve())
->driver('pdo_mysql')
->serverVersion('5.7')
->charset('utf8mb4');

// configure these for your database server
->url(env('DATABASE_URL')->resolve());
$doctrine->dbal()
->connection('customer')
->url(env('DATABASE_CUSTOMER_URL')->resolve())
->driver('pdo_mysql')
->serverVersion('5.7')
->charset('utf8mb4');

->url(env('CUSTOMER_DATABASE_URL')->resolve());
$doctrine->dbal()->defaultConnection('default');

// Entity Managers:
$doctrine->orm()->defaultEntityManager('default');
$emDefault = $doctrine->orm()->entityManager('default');
$emDefault->connection('default');
$emDefault->mapping('Main')
$defaultEntityManager = $doctrine->orm()->entityManager('default');
$defaultEntityManager->connection('default');
$defaultEntityManager->mapping('Main')
->isBundle(false)
->type('annotation')
->dir('%kernel.project_dir%/src/Entity/Main')
->prefix('App\Entity\Main')
->alias('Main');

$emCustomer = $doctrine->orm()->entityManager('customer');
$emCustomer->connection('customer');
$emCustomer->mapping('Customer')
$customerEntityManager = $doctrine->orm()->entityManager('customer');
$customerEntityManager->connection('customer');
$customerEntityManager->mapping('Customer')
->isBundle(false)
->type('annotation')
->dir('%kernel.project_dir%/src/Entity/Customer')
Expand Down