Skip to content

Commit

Permalink
Documents some important changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek committed Oct 23, 2017
1 parent e7c109d commit eb16f97
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
22 changes: 14 additions & 8 deletions src/DatabaseParsers/MysqlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ protected function getRawIndexes()
{
$result = DB::select(
'SELECT
INDEX_NAME AS name
,COUNT(1) AS TotalColumns
,GROUP_CONCAT(DISTINCT COLUMN_NAME ORDER BY SEQ_IN_INDEX ASC SEPARATOR \'|||\') AS columns
FROM INFORMATION_SCHEMA.STATISTICS AS s
WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?
GROUP BY INDEX_NAME
HAVING COUNT(1) > 1;',
INDEX_NAME AS name
,COUNT(1) AS TotalColumns
,GROUP_CONCAT(DISTINCT COLUMN_NAME ORDER BY SEQ_IN_INDEX ASC SEPARATOR \'|||\') AS columns
FROM INFORMATION_SCHEMA.STATISTICS AS s
WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?
GROUP BY INDEX_NAME
HAVING COUNT(1) > 1;',
[$this->tableName, $this->databaseName]
);

Expand Down Expand Up @@ -247,6 +247,9 @@ protected function getTransfredFields(array $columns)
$collection = [];

foreach ($columns as $column) {
// While constructing the array for each field
// there is no need to set translations for options
// or even labels. This step is handled using the FieldTransformer
$properties['name'] = $column->COLUMN_NAME;
$properties['is-nullable'] = ($column->IS_NULLABLE == 'YES');
$properties['data-value'] = $column->COLUMN_DEFAULT;
Expand All @@ -262,7 +265,7 @@ protected function getTransfredFields(array $columns)

$constraint = $this->getForeignConstraint($column->COLUMN_NAME);

$properties['foreign-constraint'] = is_null($constraint) ? null : $constraint->toArray();
$properties['foreign-constraint'] = !is_null($constraint) ? $constraint->toArray() : null;

if (intval($column->CHARACTER_MAXIMUM_LENGTH) > 255
|| in_array($column->DATA_TYPE, $this->largeDataTypes)) {
Expand All @@ -273,6 +276,9 @@ protected function getTransfredFields(array $columns)
}
$localeGroup = Helpers::makeLocaleGroup($this->tableName);
$fields = FieldTransformer::fromArray($collection, $localeGroup, $this->languages);

// At this point we constructed the fields collection with the default html-type
// We need to set the html-type using the config::getEloquentToHtmlMap() setting
$this->setHtmlType($fields);

return $fields;
Expand Down
30 changes: 18 additions & 12 deletions src/DatabaseParsers/ParserBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ abstract class ParserBase
'deleted_at',
];

/**
* The default boolean options to use.
*
* @var array
*/
protected $booleanOptions = [
'0' => 'No',
'1' => 'Yes',
];

/**
* The table name.
*
Expand Down Expand Up @@ -180,13 +170,15 @@ protected function getHtmlType($type)
* @param CrestApps\CodeGenerator\Models\Field $field
* @param string $type
*
* @return string
* @return $this
*/
protected function setHtmlType(array &$fields)
{
foreach ($fields as $field) {
$field->htmlType = $this->getHtmlType($field->getEloquentDataMethod());
}

return $this;
}

/**
Expand All @@ -210,7 +202,21 @@ protected function getModelName($tableName)
{
$modelName = ResourceMapper::pluckFirst($tableName, 'table-name', 'model-name');

return $modelName ?: ucfirst(camel_case(Str::singular($tableName)));
return $modelName ?: $this->makeModelName($tableName);
}

/**
* Make a model name from the giving table name
*
* @param string $tableName
*
* @return string
*/
protected function makeModelName($tableName)
{
$name = Str::singular($tableName);

return ucfirst(camel_case($name));
}

/**
Expand Down

0 comments on commit eb16f97

Please sign in to comment.