Skip to content

Commit e266b53

Browse files
committed
Merge pull request #1784 from dcramble/multi-em-config-2.0
Multiple Entity Managers
2 parents 3e06e0e + b255dd9 commit e266b53

File tree

1 file changed

+47
-10
lines changed

1 file changed

+47
-10
lines changed

cookbook/doctrine/multiple_entity_managers.rst

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ The following configuration code shows how you can configure two entity managers
2323
.. code-block:: yaml
2424
2525
doctrine:
26+
dbal:
27+
default_connection: default
28+
connections:
29+
default:
30+
driver: %database_driver%
31+
host: %database_host%
32+
port: %database_port%
33+
dbname: %database_name%
34+
user: %database_user%
35+
password: %database_password%
36+
charset: UTF8
37+
customer:
38+
driver: %database_driver2%
39+
host: %database_host2%
40+
port: %database_port2%
41+
dbname: %database_name2%
42+
user: %database_user2%
43+
password: %database_password2%
44+
charset: UTF8
45+
2646
orm:
2747
default_entity_manager: default
2848
entity_managers:
@@ -39,17 +59,34 @@ The following configuration code shows how you can configure two entity managers
3959
In this case, you've defined two entity managers and called them ``default``
4060
and ``customer``. The ``default`` entity manager manages entities in the
4161
``AcmeDemoBundle`` and ``AcmeStoreBundle``, while the ``customer`` entity
42-
manager manages entities in the ``AcmeCustomerBundle``.
62+
manager manages entities in the ``AcmeCustomerBundle``. You've also defined
63+
two connections, one for each entity manager.
64+
65+
.. note::
66+
67+
When working with multiple connections and entity managers, you should be
68+
explicit about which configuration you want. If you *do* omit the name of
69+
the connection or entity manager, the default (i.e. ``default``) is used.
4370

44-
When working with multiple entity managers, you should be explicit about which
45-
entity manager you want. If you *do* omit the entity manager's name when you
46-
update your schema, the default (i.e. ``default``) is used::
71+
When working with multiple connections to create your databases:
72+
73+
.. code-block:: bash
74+
75+
# Play only with "default" connection
76+
$ php app/console doctrine:database:create
77+
78+
# Play only with "customer" connection
79+
$ php app/console doctrine:database:create --connection=customer
80+
81+
When working with multiple entity managers to update your schema:
82+
83+
.. code-block:: bash
4784
4885
# Play only with "default" mappings
49-
php app/console doctrine:schema:update --force
86+
$ php app/console doctrine:schema:update --force
5087
5188
# Play only with "customer" mappings
52-
php app/console doctrine:schema:update --force --em=customer
89+
$ php app/console doctrine:schema:update --force --em=customer
5390
5491
If you *do* omit the entity manager's name when asking for it,
5592
the default entity manager (i.e. ``default``) is returned::
@@ -59,10 +96,10 @@ the default entity manager (i.e. ``default``) is returned::
5996
public function indexAction()
6097
{
6198
// both return the "default" em
62-
$em = $this->get('doctrine')->getEntityManager();
63-
$em = $this->get('doctrine')->getEntityManager('default');
64-
65-
$customerEm = $this->get('doctrine')->getEntityManager('customer');
99+
$em = $this->get('doctrine')->getManager();
100+
$em = $this->get('doctrine')->getManager('default');
101+
102+
$customerEm = $this->get('doctrine')->getManager('customer');
66103
}
67104
}
68105

0 commit comments

Comments
 (0)