Skip to content

Commit 4589a69

Browse files
committed
Fixes a bug
1 parent fb3c099 commit 4589a69

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/Commands/Bases/ResourceFileCommandBase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use CrestApps\CodeGenerator\Support\FieldTransformer;
88
use CrestApps\CodeGenerator\Support\Helpers;
99
use CrestApps\CodeGenerator\Traits\CommonCommand;
10+
use Exception;
1011
use Illuminate\Console\Command;
1112

1213
class ResourceFileCommandBase extends Command

src/DatabaseParsers/MysqlParser.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ protected function getTransfredFields(array $columns)
251251
$properties['labels'] = $this->getLabel($column->COLUMN_NAME);
252252
$properties['is-nullable'] = ($column->IS_NULLABLE == 'YES');
253253
$properties['data-value'] = $column->COLUMN_DEFAULT;
254-
$properties['data-type'] = $this->getDataType($column->DATA_TYPE);
254+
$properties['data-type'] = $this->getDataType($column->DATA_TYPE, $column->COLUMN_TYPE);
255255
$properties['data-type-params'] = $this->getPrecision($column->CHARACTER_MAXIMUM_LENGTH, $column->DATA_TYPE, $column->COLUMN_TYPE);
256256
$properties['is-primary'] = ($column->COLUMN_KEY == 'PRIMARY KEY');
257257
$properties['is-index'] = ($column->COLUMN_KEY == 'MUL');
@@ -313,13 +313,18 @@ protected function getPrecision($length, $dataType, $columnType)
313313
* Gets the data type for a giving field.
314314
*
315315
* @param string $type
316+
* @param string $columnType
316317
*
317318
* @return $this
318319
*/
319-
protected function getDataType($type)
320+
protected function getDataType($type, $columnType)
320321
{
321322
$map = Config::dataTypeMap();
322323

324+
if ($columnType == 'tinyint(1)') {
325+
return 'boolean';
326+
}
327+
323328
if (!array_key_exists($type, $map)) {
324329
throw new Exception("The type " . $type . " is not mapped in the 'eloquent_type_to_method' key in the config file.");
325330
}
@@ -361,7 +366,7 @@ protected function getForeignConstraint($name)
361366
*/
362367
protected function getHtmlOptions($dataType, $columnType)
363368
{
364-
if ($dataType == 'tinyint(1)') {
369+
if ($columnType == 'tinyint(1)') {
365370
return $this->getBooleanOptions();
366371
}
367372

src/Support/Helpers.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@ public static function prettifyJson(array $object)
6868
public static function convertNameToLabel($name)
6969
{
7070
$title = ucwords(str_replace('_', ' ', $name));
71+
$idString = ' Id';
7172

72-
return rtrim($title, ' Id');
73+
if (ends_with($title, $idString)) {
74+
return rtrim($title, $idString);
75+
}
76+
77+
return $title;
7378
}
7479

7580
/**

0 commit comments

Comments
 (0)