Allow make:entity specify the table name#1635
Conversation
make:entity specify the table name
|
Struggling with tools in local but i'm going to have a look and those errors |
| } | ||
|
|
||
| public function generateEntityClass(ClassNameDetails $entityClassDetails, bool $apiResource, bool $withPasswordUpgrade = false, bool $generateRepositoryClass = true, bool $broadcast = false, EntityIdTypeEnum $useUuidIdentifier = EntityIdTypeEnum::INT): string | ||
| public function generateEntityClass(ClassNameDetails $entityClassDetails, bool $apiResource, bool $withPasswordUpgrade = false, bool $generateRepositoryClass = true, bool $broadcast = false, EntityIdTypeEnum $useUuidIdentifier = EntityIdTypeEnum::INT, ?string $tableName): string |
There was a problem hiding this comment.
| public function generateEntityClass(ClassNameDetails $entityClassDetails, bool $apiResource, bool $withPasswordUpgrade = false, bool $generateRepositoryClass = true, bool $broadcast = false, EntityIdTypeEnum $useUuidIdentifier = EntityIdTypeEnum::INT, ?string $tableName): string | |
| public function generateEntityClass(ClassNameDetails $entityClassDetails, bool $apiResource, bool $withPasswordUpgrade = false, bool $generateRepositoryClass = true, bool $broadcast = false, EntityIdTypeEnum $useUuidIdentifier = EntityIdTypeEnum::INT, ?string $tableName = null): string |
src/Maker/MakeEntity.php
Outdated
| ->addOption('broadcast', 'b', InputOption::VALUE_NONE, 'Add the ability to broadcast entity updates using Symfony UX Turbo?') | ||
| ->addOption('regenerate', null, InputOption::VALUE_NONE, 'Instead of adding new fields, simply generate the methods (e.g. getter/setter) for existing fields') | ||
| ->addOption('overwrite', null, InputOption::VALUE_NONE, 'Overwrite any existing getter/setter methods') | ||
| ->addOption('table-name', null, InputOption::VALUE_NONE, 'Overwrite default table name') |
There was a problem hiding this comment.
| ->addOption('table-name', null, InputOption::VALUE_NONE, 'Overwrite default table name') | |
| ->addOption('table-name', 't', InputOption::VALUE_NONE, 'Overwrite default table name') |
| ); | ||
|
|
||
| $tableName = $this->doctrineHelper->getPotentialTableName($entityClassDetails->getFullName()); | ||
| if (null === $tableName) { |
There was a problem hiding this comment.
Wouldn't you consider handling the most common case of pluralizing the class name somehow? Maybe via another option or something else? You can use this Symfony inflector capability.
There was a problem hiding this comment.
This is a good point. But I think it's outside the scope of this PR, my purpose is to be able to explicitly choose the table name, not to change the default behavior. Both can also coexist, I think.
There was a problem hiding this comment.
I keep the idea to open a new PR in the next few days, or maybe you want to do it
| } | ||
|
|
||
| public function generateEntityClass(ClassNameDetails $entityClassDetails, bool $apiResource, bool $withPasswordUpgrade = false, bool $generateRepositoryClass = true, bool $broadcast = false, EntityIdTypeEnum $useUuidIdentifier = EntityIdTypeEnum::INT): string | ||
| public function generateEntityClass(ClassNameDetails $entityClassDetails, bool $apiResource, bool $withPasswordUpgrade = false, bool $generateRepositoryClass = true, bool $broadcast = false, EntityIdTypeEnum $useUuidIdentifier = EntityIdTypeEnum::INT, string $tableName = null): string |
There was a problem hiding this comment.
| public function generateEntityClass(ClassNameDetails $entityClassDetails, bool $apiResource, bool $withPasswordUpgrade = false, bool $generateRepositoryClass = true, bool $broadcast = false, EntityIdTypeEnum $useUuidIdentifier = EntityIdTypeEnum::INT, string $tableName = null): string | |
| public function generateEntityClass(ClassNameDetails $entityClassDetails, bool $apiResource, bool $withPasswordUpgrade = false, bool $generateRepositoryClass = true, bool $broadcast = false, EntityIdTypeEnum $useUuidIdentifier = EntityIdTypeEnum::INT, ?string $tableName = null): string |
Missed the ? here :)
src/Maker/MakeEntity.php
Outdated
| ->addOption('broadcast', 'b', InputOption::VALUE_NONE, 'Add the ability to broadcast entity updates using Symfony UX Turbo?') | ||
| ->addOption('regenerate', null, InputOption::VALUE_NONE, 'Instead of adding new fields, simply generate the methods (e.g. getter/setter) for existing fields') | ||
| ->addOption('overwrite', null, InputOption::VALUE_NONE, 'Overwrite any existing getter/setter methods') | ||
| ->addOption('table-name', 't', InputOption::VALUE_NONE, 'Overwrite default table name') |
There was a problem hiding this comment.
Overwrite seems more something to change existing things no ?
I'd say this will be also (mainly?) used during first Entitiy creation ?
Maybe something more like "Set custom table name" ?
Feel free to ignore if you disagree, just a comment passing by ;)
There was a problem hiding this comment.
To be honest I hadn't thought that far ahead. But I agree with you for this change, sounds better
| ->addOption('broadcast', 'b', InputOption::VALUE_NONE, 'Add the ability to broadcast entity updates using Symfony UX Turbo?') | ||
| ->addOption('regenerate', null, InputOption::VALUE_NONE, 'Instead of adding new fields, simply generate the methods (e.g. getter/setter) for existing fields') | ||
| ->addOption('overwrite', null, InputOption::VALUE_NONE, 'Overwrite any existing getter/setter methods') | ||
| ->addOption('table-name', 't', InputOption::VALUE_NONE, 'Set custom table name') |
There was a problem hiding this comment.
| ->addOption('table-name', 't', InputOption::VALUE_NONE, 'Set custom table name') | |
| ->addOption('table-name', 't', InputOption::VALUE_REQUIRED, 'Set custom table name') |
This is the reason of the test failures I think.
But i'm wondering here... should we add a test to avoid using an existing table name ?
|
Sorry, I didn't see this. I created a PR with a very similar approach, but currently is failing the test (CI/CD is fine). I don't know what the next steps are, beyond just waiting... Thanks in advance. |
Give a try on #1626