0

When using the MakerBundle in Symfony (4) to create new entity (make:entity EntityName), an id is generated by default with annotation (if annotations enabled) @GeneratedValue.

@GeneratedValue means @GeneratedValue(strategy="AUTO").

According to the Doctrine documentation, the AUTO strategy is supposed to use SERIAL type for the id in PostgreSQL. But, I do not know why in my case, the AUTO strategy use SEQUENCE for the id.

Then, I can force it to use SERIAL by changing by hand into @GeneratedValue(strategy="IDENTITY") which means using SERIAL type in PostgreSQL.

Is there any way to change the default @GeneratedValue annotation created by the MakerBundle for the new entities to be created with the @GeneratedValue(strategy="IDENTITY") annotation ?

robinvrd
  • 1,760
  • 12
  • 28

1 Answers1

0

What you could possibly do is decorate \Symfony\Bundle\MakerBundle\Doctrine\EntityClassGenerator which is registered as a service named maker.entity_class_generator in vendor/symfony/maker-bundle/src/Resources/config/services.xml and override its generateEntityClass method to make a different call on the Generator's generateClass method, specifically the file path could be changed there.

Seems like the file path there could be relative or absolute, so with some trial and error you could get it to output the annotation you want. The template that the maker bundle uses now is at vendor/symfony/maker-bundle/src/Resources/skeleton/doctrine/Entity.tpl.php, and it's pretty straightforward to modify.

kix
  • 3,290
  • 27
  • 39