-
-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow make:entity
specify the table name
#1635
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,15 +40,17 @@ public function __construct( | |
) { | ||
} | ||
|
||
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 | ||
{ | ||
$repoClassDetails = $this->generator->createClassNameDetails( | ||
$entityClassDetails->getRelativeName(), | ||
'Repository\\', | ||
'Repository' | ||
); | ||
|
||
$tableName = $this->doctrineHelper->getPotentialTableName($entityClassDetails->getFullName()); | ||
if (null === $tableName) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I keep the idea to open a new PR in the next few days, or maybe you want to do it |
||
$tableName = $this->doctrineHelper->getPotentialTableName($entityClassDetails->getFullName()); | ||
} | ||
|
||
$useStatements = new UseStatementGenerator([ | ||
$repoClassDetails->getFullName(), | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -97,6 +97,7 @@ | |||||
->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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
->setHelp($this->getHelpFileContents('MakeEntity.txt')) | ||||||
; | ||||||
|
||||||
|
@@ -189,11 +190,12 @@ | |||||
$classExists = class_exists($entityClassDetails->getFullName()); | ||||||
if (!$classExists) { | ||||||
$broadcast = $input->getOption('broadcast'); | ||||||
$entityPath = $this->entityClassGenerator->generateEntityClass( | ||||||
Check failure on line 193 in src/Maker/MakeEntity.php GitHub Actions / PHPStan
|
||||||
entityClassDetails: $entityClassDetails, | ||||||
apiResource: $input->getOption('api-resource'), | ||||||
broadcast: $broadcast, | ||||||
useUuidIdentifier: $this->getIdType(), | ||||||
tableName: $input->getOption('table-name') | ||||||
); | ||||||
|
||||||
if ($broadcast) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.