Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2: Add another namespace to Entity namespaces

In my symfony2 application, I have two database connections, I'd like to keep the entity classes seperate and therefore have one set of entity classes in one bundle and another set in another bundle. However when trying to call my bundle, its for some reason not registered as an Entity Namespace, the error is as follows:

Unknown Entity namespace alias 'AcmeStaffBundle'.
500 Internal Server Error - ORMException 

I have looked for where it sets the entity namespaces, and i've found it to be in the cached files

$e = new \Doctrine\ORM\Configuration();
$e->setEntityNamespaces(array('AcmeStoreBundle' => 'Acme\\StoreBundle\\Entity'));

How can i add this to array?

NEW EDIT:

My config.yml is as follows which should help clarify the issue:

orm:
    entity_managers:
        default:
            connection:       default
            mappings:
                AcmeStoreBundle: ~
        Foo:
            connection:       Foo
            mappings:
                AcmeFooBundle: ~

Thanks in advance

like image 912
Matt Avatar asked Dec 19 '11 17:12

Matt


1 Answers

I had this exact problem while trying to use the generated CRUD forms. What finally solved the problem was adding the name of the preferred entity manager as a parameter to getEntityManager() like this:

$em = $this->getDoctrine()->getEntityManager('Foo');
like image 177
Kaivosukeltaja Avatar answered Nov 11 '22 11:11

Kaivosukeltaja