for the current project that I am going to work on, I need to create many entities using the make:entity command.
Each time a new entity is created it needs to have the following columns that need to be defined
- id_owner
- sys_date_created
- sys_date_modified
- date_created
- date_modified
- id_group
- id_user
The problem is that I will have to enter each of the following fields every time I create a new entity.
I have been looking at symfony and doctrine documentation if it is possible to override the make:entity function but to no avail.
What I would like is that each time we generate a new entity, the aboved mentioned fields are automatically generated.
For ex just the column id that is generated automatically by symfony.
If anyone has any working code or link to share that would be great.
Thanks in advance
2
Answers
I took a look at the maker bundle’s Generator class and it turns out that there is a reasonable solution to override the templates being used.
The generator’s code has:
So when looking for a template file the generator first looks in the current directory and then in the maker bundle’s Resources/skeleton directory. So in your applications main directory make a directory called doctrine, copy in the default template file and edit to suit. For example
After which the make:entity command will pick up your own custom template. It is not a perfect solution. If the maker bundle updates the template then you will need to update yours. Also it would be nice if you could tell the generator where to look but it does work.
I would suggest to use an
MappedSuperclass
and extend it in your entities.Example:
This still enables you to use the maker bundle to create entities. However, after creating it, don’t forget to extend the
MappedSuperclass
class.In the docs you can find some more details about inheritance mapping.