@@ -42,8 +42,17 @@ and ``customer``. The ``default`` entity manager manages entities in the
42
42
manager manages entities in the ``AcmeCustomerBundle ``.
43
43
44
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
46
- asking for it, the default entity manager (i.e. ``default ``) is returned::
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::
47
+
48
+ # Play only with "default" mappings
49
+ php app/console doctrine:schema:update --force
50
+
51
+ # Play only with "customer" mappings
52
+ php app/console doctrine:schema:update --force --em=customer
53
+
54
+ If you *do * omit the entity manager's name when asking for it,
55
+ the default entity manager (i.e. ``default ``) is returned::
47
56
48
57
class UserController extends Controller
49
58
{
@@ -52,11 +61,34 @@ asking for it, the default entity manager (i.e. ``default``) is returned::
52
61
// both return the "default" em
53
62
$em = $this->get('doctrine')->getEntityManager();
54
63
$em = $this->get('doctrine')->getEntityManager('default');
55
-
64
+
56
65
$customerEm = $this->get('doctrine')->getEntityManager('customer');
57
66
}
58
67
}
59
68
60
69
You can now use Doctrine just as you did before - using the ``default `` entity
61
70
manager to persist and fetch entities that it manages and the ``customer ``
62
71
entity manager to persist and fetch its entities.
72
+
73
+ The same applies to repository call::
74
+
75
+ class UserController extends Controller
76
+ {
77
+ public function indexAction()
78
+ {
79
+ // Retrieves a repository managed by the "default" em
80
+ $products = $this->get('doctrine')
81
+ ->getRepository('AcmeStoreBundle:Product')
82
+ ->findAll();
83
+
84
+ // Explicit way to deal with the "default" em
85
+ $products = $this->get('doctrine')
86
+ ->getRepository('AcmeStoreBundle:Product', 'default')
87
+ ->findAll();
88
+
89
+ // Retrieves a repository managed by the "customer" em
90
+ $customers = $this->get('doctrine')
91
+ ->getRepository('AcmeCustomerBundle:Customer', 'customer')
92
+ ->findAll();
93
+ }
94
+ }
0 commit comments