I try to work with two entity managers for the same bundle. My configuration is like this:
orm:
default_entity_manager: default
entity_managers:
electra:
connection: electra
mappings:
XXDemoBundle: ~
default:
connection: default
mappings:
XXDemoBundle: ~
Is there any way to tell wich entites belong to which entity manager? It crashes now if I want to work with a table which doens't belong to the default entity manager.
Thanks
- UPDATE
here is my configuration for the connection:
doctrine:
dbal:
default_connection: default
connections:
default:
dbname: old_project
user: root
password: 123123
host: 1.1.1.1
port: 1
electra:
dbname: electra
user: root
password: 123123
host: 2.2.2.2
port: 2
orm:
default_entity_manager: electra
entity_managers:
electra:
connection: electra
mappings:
XXDemoBundle: ~
default:
connection: default
mappings:
XXDemoBundle: ~
Ok. Tried to edit your original post but it's waiting for peer review. Not sure how long that takes. Try changing your config to:
Now completely blow away your cache just to be sure then run:
You should get identical results. I tested this on my system so I'm fairly certain that if you don't then you have some typo somewhere.
So mapping info is working. Next step is to verify that both databases match your entity schema. So do this:
Neither should produce any output. If one does then it means your database does not match your entities and that needs to be resolved (possibly using the --force option) before queries will work.
Once the databases are in sync then you should probably use doctrine:query:dql and do a test query against both managers. Then go back into your code.
=========================================
It has now been understood that the real goal is to have two entity managers point to the same set of entities but somehow indicate that each entity manager should limit itself to a certain set of those entities. And that is not something the S2 supports out of the box.
You could look through the Doctrine manual and see how it handles the entity metadata and maybe do something with that but that could get complicated.
The only thing that S2 really offers is the ability to bind an entity manager to all the entities in one or more bundles using the mapping attribute. If you wanted to share say three of seven entities from one bundle with another bundle then you would simply recreate those entities in the second bundle. Possibly by extending the class so as to avoid code duplication.
I think you might want to alter your approach a bit. If you have a set of core entities shared with multiple bundles then put those in their own bundle. Each follow on bundle can then add additional entities.
For using multiple entitymanager in same bundle you have to config mapping options for each entitymanager.
http://symfony.com/doc/current/reference/configuration/doctrine.html
Exemple off config file
You can now use console for managing your db with the --em parameter
Ex : update database for shop entitymanager
Read mapping information from Your\Bundle\Entity\SecondDb
Ex : update database for default entitymanager
Read mapping information from Your\Bundle\Entity\FirstDb