Entity MetaData for Doctrine and multiple Entity Managers

302 Views Asked by At

I'm trying to setup an Sql Server connection for Doctrine in Symfony2.However I can not figure out how to setup some Entity Foo to be managed by the new Entity Manager. I have seen this post in regards to managing Entities with multiple Entity Managers, however I don't know how to use it with different Entity Managers like this. What metadata should I use so I can handle some of My entities with the new Entity Manager?

1

There are 1 best solutions below

1
On BEST ANSWER

You can put Foo entity to separate bundle i.e MyFooBundle (if you have single core/app bundle) and map the bundle to other entity manager.

Disable auto mapping and configure connections at config.yml then define the entity managers and mapping

doctrine:
    dbal:
        connections:
            default:
                driver:   %database_driver%
                host:     %database_host%
                dbname:   %database_name%
                user:     %database_user%
                password: %database_password%
                charset:  UTF8
            other:
                driver:   %database_driver_2%
                host:     %database_host_2%
                dbname:   %database_name_2%
                user:     %database_user_2%
                password: %database_password_2%
                charset:  UTF8
    orm:
        entity_managers:
            default:
                connection: default
                mappings:
                   FOSUserBundle: ~
                   AppBundle: ~
            other:
               connection: other
               mappings:
                   MyFooBundle: ~