-
Notifications
You must be signed in to change notification settings - Fork 72
Multiple Entity Managers and Connections #55
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
base: master
Are you sure you want to change the base?
Conversation
653df26
to
20a4bff
Compare
Added a new configuration directive entity_managers that allows for individual configuration of multiple entity managers. This entry will be created automatically if no entity_managers entry is defined If present each entity manager must be given a name. An entity manager has the following configuration options:
|
Any update on whether this will be merged or not? This looks very handy to me. |
If tests can be written to manage all the changes, then we can move forward with the implementation / merge. |
👍 |
@kirkbushel Do you have a list of tests or features you would like tests added for? Since the old configuration is rebuild into the new format the old test should confirm that basic functionality is still intact. |
I do not believe there are any tests for the commands yet - so that would be a good starting point. Would be great to increase our test count and coverage. |
@kirkbushell Sorry this took so long. I needed to do a little refactoring in order to make it more testable. Let me know your thoughts on this and / or any feedback on any additional tests you need in order to move this forward. |
Along with the From http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html
|
http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html states that a default entity manager should be created An em option has been added to commands
@FoxxMD You are correct. Instead of creating an entity manager for the default database we now create a new entry in $app['config']'doctrine::doctrine' called So the thing to note is if you create an 'entity_managers' entry in doctrine.php it requires its own configuration. Missing items will be filled with some defaults. You then need to set a name for the entity manager and list the matching connection from $app['config']['database'] if they are not the name. Doctrine does not require that the connection and entity name be the same so this provides a little more flexibility. You still need to define the default_connection in doctrine.php outside of the entity_managers array if for some reason this is different from the default connection in $app['config']['database']. If default_connection is not specified then it will be created with from the default value from $app['config']['database']. If you have any questions/comments I'd be happy to review it. |
@FoxxMD \Tests\MultipleEntityManagersAndConnections\SchemaCreateCommandTest uses the following connection information. It will call the command with sqlite to use a non-default entity manager for the operation. For reference the test adds the following to doctrine.php.
|
Thanks @npmarrin ! How do I get a non-default entity manager from code? Right now I'm just using the |
@FoxxMD You can get the default manager using You can review http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html if you need more background. If you have any issues / concerns let me know. It is great to get another pair of eyes on this. |
Thanks @npmarrin, this has been extremely helpful! |
This patch provides the ability to reference multiple database connections in laravel-doctrine. It will register the default database or the set of databases outlined in the entity_managers configuration. Existing functionality is maintained by continuing to register the EntityManager and returning a connection from the ManagerRegistry