Sam
Sam

Reputation: 122

How to generate Entity with all fields from db table automatically?

I am trying to generate Entity from database but it only add id automatically. Is there any console command to automatically generate entity with all fields from db?

Upvotes: 0

Views: 660

Answers (2)

Jeet
Jeet

Reputation: 1587

Yes, You can use Doctrine reverse engineering available in Symfony SE. Check the doc here.

The command will be :

php bin/console doctrine:mapping:import --force AcmeBlogBundle xml

Where The ORM entities will be imported to AcmeBlogBundle with xml format. you can change the format of your ORM later with annother command. Please check the document for full usage.

Note :

  • It's not guranteed, that all your field will be imported. Its all dependent on database mapping.
  • All your tables in database will be imported to ORM entities. I didn't see an option to filter one or few tables from database.

Upvotes: 2

Alvin Bunk
Alvin Bunk

Reputation: 7764

There is a console command below to automatically generate setter/getters etc... for an Entity class that you've created:

php bin/console doctrine:generate:entities AppBundle/Entity/Product

In the above example, the file under 'src/AppBundle/Entity/Product.php' would be the Entity class.

Is this what you were looking for?

Upvotes: 0

Related Questions