Skip to content

Commit eb16f97

Browse files
committed
Documents some important changes
1 parent e7c109d commit eb16f97

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

src/DatabaseParsers/MysqlParser.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ protected function getRawIndexes()
110110
{
111111
$result = DB::select(
112112
'SELECT
113-
INDEX_NAME AS name
114-
,COUNT(1) AS TotalColumns
115-
,GROUP_CONCAT(DISTINCT COLUMN_NAME ORDER BY SEQ_IN_INDEX ASC SEPARATOR \'|||\') AS columns
116-
FROM INFORMATION_SCHEMA.STATISTICS AS s
117-
WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?
118-
GROUP BY INDEX_NAME
119-
HAVING COUNT(1) > 1;',
113+
INDEX_NAME AS name
114+
,COUNT(1) AS TotalColumns
115+
,GROUP_CONCAT(DISTINCT COLUMN_NAME ORDER BY SEQ_IN_INDEX ASC SEPARATOR \'|||\') AS columns
116+
FROM INFORMATION_SCHEMA.STATISTICS AS s
117+
WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?
118+
GROUP BY INDEX_NAME
119+
HAVING COUNT(1) > 1;',
120120
[$this->tableName, $this->databaseName]
121121
);
122122

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

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

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

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

267270
if (intval($column->CHARACTER_MAXIMUM_LENGTH) > 255
268271
|| in_array($column->DATA_TYPE, $this->largeDataTypes)) {
@@ -273,6 +276,9 @@ protected function getTransfredFields(array $columns)
273276
}
274277
$localeGroup = Helpers::makeLocaleGroup($this->tableName);
275278
$fields = FieldTransformer::fromArray($collection, $localeGroup, $this->languages);
279+
280+
// At this point we constructed the fields collection with the default html-type
281+
// We need to set the html-type using the config::getEloquentToHtmlMap() setting
276282
$this->setHtmlType($fields);
277283

278284
return $fields;

src/DatabaseParsers/ParserBase.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ abstract class ParserBase
2929
'deleted_at',
3030
];
3131

32-
/**
33-
* The default boolean options to use.
34-
*
35-
* @var array
36-
*/
37-
protected $booleanOptions = [
38-
'0' => 'No',
39-
'1' => 'Yes',
40-
];
41-
4232
/**
4333
* The table name.
4434
*
@@ -180,13 +170,15 @@ protected function getHtmlType($type)
180170
* @param CrestApps\CodeGenerator\Models\Field $field
181171
* @param string $type
182172
*
183-
* @return string
173+
* @return $this
184174
*/
185175
protected function setHtmlType(array &$fields)
186176
{
187177
foreach ($fields as $field) {
188178
$field->htmlType = $this->getHtmlType($field->getEloquentDataMethod());
189179
}
180+
181+
return $this;
190182
}
191183

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

213-
return $modelName ?: ucfirst(camel_case(Str::singular($tableName)));
205+
return $modelName ?: $this->makeModelName($tableName);
206+
}
207+
208+
/**
209+
* Make a model name from the giving table name
210+
*
211+
* @param string $tableName
212+
*
213+
* @return string
214+
*/
215+
protected function makeModelName($tableName)
216+
{
217+
$name = Str::singular($tableName);
218+
219+
return ucfirst(camel_case($name));
214220
}
215221

216222
/**

0 commit comments

Comments
 (0)