Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 4 getter setter not generated from existing database

I know that to generate entity from existing database in symfony 4, just execute this command :

> php bin/console doctrine:generate:entities

but this command dont generate getter setter, just generate variable from column.

and of course I must use some dirty work to create it manually.

may be I missed read the documentation, how to generate entities getter setter from existing database using doctrine symfony 4?

like image 548
yozawiratama Avatar asked Oct 20 '25 12:10

yozawiratama


2 Answers

To generate entity classes from an existing database you need to ask Doctrine to introspect the database and generate the corresponding metadata files. Metadata files describe the entity class to generate based on table fields.

> php bin/console doctrine:mapping:import App\\Entity annotation --path=src/Entity

This command will generate new PHP classes with annotation metadata into src/Entity To generate the missing getter/setter methods (or to create the classes if neceesary), run:

> php bin/console make:entity --regenerate App

Also check Official documentation

like image 62
Vladislav Cherednichenko Avatar answered Oct 23 '25 06:10

Vladislav Cherednichenko


DOC says: "If you prefer to add new properties manually, the make:entity command can generate the getter & setter methods for you:

php bin/console make:entity --regenerate

If you make some changes and want to regenerate all getter/setter methods, also pass --overwrite."

Also note that with Symfony 3 (I don't about v4), the doctrine:generate:entities did not work with protected properties

like image 21
Roubi Avatar answered Oct 23 '25 07:10

Roubi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!