Pete
Pete

Reputation: 564

Doctrine2 / Symfony2 - Using different databases per bundle

How can I use different databases in every single bundle of Symfony2 with Doctrine2?

FooBundle <- Database "Foo"

BarBundle <- Database "Bar"

Upvotes: 4

Views: 1601

Answers (1)

Ahmed Siouani
Ahmed Siouani

Reputation: 13891

This may help How to work with Multiple Entity Managers and Connections.

So you can define multiple Entity Managers related to your databases connections, you can then map your bundle(s) to the right Entity Manager.

The examples on the documentation are well explained.

doctrine:
    dbal:
        default_connection:   foo_connection
        connections:
            foo_connection:
                # ...
                # Foo connection parameters
                # ...
            bar_connection:
                # ...
                # Bar connection parameters
                # ...

    orm:
        default_entity_manager:   foo_manager
        entity_managers:
            foo_manager:
                connection:        foo_connection
                mappings:
                    FooBundle: ~
            bar_manager:
                connection:       bar_connection
                mappings:
                    BarBundle: ~

Upvotes: 6

Related Questions