Skip to content

Commit

Permalink
feat(backend) Avoid column duplications.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Sep 6, 2017
1 parent 28081df commit a1bdf67
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/Backend/PlantUML.php
Expand Up @@ -59,17 +59,26 @@ public function visitTable(Frontend\Table $table, &$handle = null, &$eldnah = nu

$maximumTabulation = 1 + (int) floor($maximumNameLength / 4);

$listedColumns = [];

foreach ($columns as $column) {
$out .= sprintf(
' {field} %s%s%s%s%s' . "\n",
0 !== preg_match($column::PRIMARY, $column->constraintName ?? '') ? '+' : '',
$column->name,
str_repeat("\t", max(1, $maximumTabulation - (int) (floor(strlen($column->name) / 4)))),
$column->isNullable ? '?' : '',
$column->type
);

if (null !== $column->referencedTableName &&
$isPrimary = 0 !== preg_match($column::PRIMARY, $column->constraintName ?? '');

if (false === in_array($column->name, $listedColumns)) {
$out .= sprintf(
' {field} %s%s%s%s%s' . "\n",
$isPrimary ? '+' : '',
$column->name,
str_repeat("\t", max(1, $maximumTabulation - (int) (floor(strlen($column->name) / 4)))),
$column->isNullable ? '?' : '',
$column->type
);

$listedColumns[] = $column->name;
}

if (false === $isPrimary &&
null !== $column->referencedTableName &&
null !== $column->referencedColumnName) {
$connections .=
$column->referencedTableName . ' <-- ' . $table->name .
Expand Down

0 comments on commit a1bdf67

Please sign in to comment.