Skip to content

Commit

Permalink
Fix up index/view for enums.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Dec 28, 2023
1 parent 1df72e6 commit 36afd65
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/Command/EnumCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace Bake\Command;

use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use Cake\Utility\Inflector;
use InvalidArgumentException;
Expand Down Expand Up @@ -174,4 +175,26 @@ protected function formatCases(array $cases): array

return $formatted;
}

/**
* Generate a class stub
*
* @param string $name The class name
* @param \Cake\Console\Arguments $args The console arguments
* @param \Cake\Console\ConsoleIo $io The console io
* @return void
*/
protected function bake(string $name, Arguments $args, ConsoleIo $io): void
{
parent::bake($name, $args, $io);

$path = $this->getPath($args);
$filename = $path . $name . '.php';

// Work around composer caching that classes/files do not exist.
// Check for the file as it might not exist in tests.
if (file_exists($filename)) {
require_once $filename;
}
}
}
6 changes: 6 additions & 0 deletions src/Command/ModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,12 @@ protected function possibleEnumFields(TableSchemaInterface $schema): array

foreach ($schema->columns() as $column) {
$columnSchema = $schema->getColumn($column);
if (str_starts_with($columnSchema['type'], 'enum-')) {
$fields[] = $column;

Check warning on line 1443 in src/Command/ModelCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/ModelCommand.php#L1443

Added line #L1443 was not covered by tests

continue;

Check warning on line 1445 in src/Command/ModelCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/ModelCommand.php#L1445

Added line #L1445 was not covered by tests
}

if (!in_array($columnSchema['type'], ['string', 'integer', 'tinyinteger', 'smallinteger'], true)) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/BakeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function getViewFieldsData(array $fields, SchemaInterface $schema, array
if (isset($associationFields[$field])) {
return 'string';
}
if (str_starts_with($type, 'enum-')) {
if ($type && str_starts_with($type, 'enum-')) {
return 'enum';
}
$numberTypes = ['decimal', 'biginteger', 'integer', 'float', 'smallinteger', 'tinyinteger'];
Expand Down

0 comments on commit 36afd65

Please sign in to comment.