Creating doctrine objects in a separate namespace

I follow the documentation here:

These are teams

php app/console doctrine:mapping:convert xml ./src/Acme/BlogBundle/Resources/config/doctrine/metadata/orm --from-database --force php app/console doctrine:mapping:import AcmeBlogBundle annotation php app/console doctrine:generate:entities AcmeBlogBundle 

I see new objects here in

 Acme/BlogBundle/AcmeBlogBundle/Entity 

But I wanted to know how to add Entities to their own namespace like this.

 Acme/BlogBundle/AcmeBlogBundle/Entity/Foo Acme/BlogBundle/AcmeBlogBundle/Entity/Bar 

This means that I could separate entities for the Foo and Bar databases.

UPDATE:

Or it should be structured as follows:

 Acme/BlogBundle/AcmeBlogBundle/Foo/Entity Acme/BlogBundle/AcmeBlogBundle/Bar/Entity 

Thoughts?

0
php namespaces symfony entity doctrine
Nov 29 '12 at 16:14
source share
1 answer

If you look in the section โ€œHow to work with several managers and community connectionsโ€ in the documentation, you will notice that you can bind your package objects to one or many object managers . Each of them is associated with a specific connection to the database.

If, for example, I defined two database connections (first_connection and second_connection), I can add two entity managers, as follows,

 entity_managers: first_manager: connection: first_connection mappings: MyBundle: dir: Path/To/EntityFolder/Foo/ second_manager: connection: second_connection mappings: MyBundle: dir: Path/To/EntityFolder/Bar/ 

You can then specify which correct Entity Manager to use during the first two steps of the entity creation process,

 php app/console doctrine:mapping:convert xml ./src/Acme/BlogBundle/Resources/config/doctrine/metadata/orm --from-database --force --em=first_manager --filter=MyTable 

Note. The --filter used so that you can create your objects individually.

 php app/console doctrine:mapping:import AcmeBlogBundle annotation --em=first_manager --filter=MyTable php app/console doctrine:generate:entities AcmeBlogBundle 

Then your entities are placed in the necessary folders in accordance with the connection to which they are attached.

+7
Nov 29 '12 at 20:41
source share



All Articles