Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating a single Entity from existing database using symfony2 and doctrine

Is it possible to generate a single entity from database using the Symfony2 console tool?

In the middle of coding I had to add a table and there are modifications made to the existing entity classes. So I don't want all my entities regenerated.

Any suggestions will be appreciated!

like image 488
Sethunath K M Avatar asked Apr 29 '12 11:04

Sethunath K M


People also ask

What is doctrine database?

The Doctrine Project is the home to several PHP libraries primarily focused on database storage and object mapping. The core projects are the Object Relational Mapper (ORM) and the Database Abstraction Layer (DBAL) it is built upon.

What is Entity Manager in doctrine?

Doctrine's public interface is through the EntityManager . This class provides access points to the complete lifecycle management for your entities, and transforms entities from and back to persistence. You have to configure and create it to use your entities with Doctrine ORM.


2 Answers

I had the same problem, you've to do this way:

php app/console doctrine:mapping:convert metadata_format \     ./src/App/MyBundle/Resources/config/doctrine \     --from-database \     --filter="Yourtablename" 

Then

php app/console doctrine:mapping:import AppMyBundle \     metadata_format --filter="Yourtablename" 

Where metadata_format is the file ending you want to generate (e.g. xml, yml, annotation)

And finally

php app/console doctrine:generate:entities AppMyBundle --no-backup 

Like this doctrine will load only the entity you need. Just be carefull on the filter you must use the CamelCase !

Hope this will help you

like image 131
Snroki Avatar answered Oct 03 '22 00:10

Snroki


For the third command, doctrine kept regenerating all of the Entity files. By adding the entity name after the bundle, it only generated the entity I was interested in.

php app/console doctrine:generate:entities AppMyBundle:Yourtablename --no-backup 
like image 35
jpb Avatar answered Oct 03 '22 00:10

jpb