I have an app that talks to two different databases. For one of my entities, School, I get the following error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'pressbox.schools' doesn't exist
That makes sense because there is no pressbox.schools. It’s fnt.schools. It’s trying to talk to the wrong database.
How do I tell my entity which mapping I want it to use? I would of course rather refer to the mappings than to the database names themselves, which can be different depending on the environment.
First, declare your connections in a config file (config.yml would be fine):
Then declare the entity managers:
Now, in a controller, you can tell Doctrine which entity manager to use by passing its name to
getEntityManager():Assuming the entity manager for the fnt table is called that same name.