1

In my Symfony2 browsergame I have an user entity using the Doctrine 2 ORM. The game has two instances, classic and speed, which are mainly independent from each other and are using both its own databases (same structure). The only problem is that users are able to connect their accounts, so some basic user informations of the connected account shall be shown. For that I have a classic_id and speed_id as properties which connect to another user entity. But that would be a a cross database join which is not possible in Doctrine 2 as far as I found out. I also found that it is possible to have multiple entity managers with their own connections, but I think they can only be applied to complete bundles, right?

So here I need some workaround for that problem, what is the easiest way to do that?

1
  • Or just skip the ORM query builder and use the DBAL. Not sure how was it back then, but nowadays I think you don't have to even specify DB config if it's using default config; but adding that second_db: line to doctrine.yaml won't hurt anything :-) Commented Jan 24, 2024 at 14:17

1 Answer 1

2

Actually there is possibility to do cross db joins, but it's rather trick than a feature and I do not recommend use it.

To separate entities from one bundle between different entity managers you can use "dir" attribute which points to managed entities. For example:

doctrine:
    orm:
        default_entity_manager:   default
        entity_managers:
            default:
                connection:       default
                mappings:
                    AppBundle:
                        dir:      Path/To/EntityFolder1
            anotherone:
                connection:       anotherconnection
                mappings:
                    AppBundle:
                        dir:      Path/To/EntityFolder2

There is also poor documented "prefix" option, but I didn't figure out what it is yet (you can experiment by yourself:))

Greetings!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.