Skip to content

use native schema methods to get model's columns #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 8 additions & 24 deletions src/GraphBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GraphBuilder
* @param $models
* @return Graph
*/
public function buildGraph(Collection $models) : Graph
public function buildGraph(Collection $models): Graph
{
$this->graph = new Graph();

Expand All @@ -32,40 +32,23 @@ public function buildGraph(Collection $models) : Graph

protected function getTableColumnsFromModel(EloquentModel $model)
{
try {

$table = $model->getConnection()->getTablePrefix() . $model->getTable();
$schema = $model->getConnection()->getDoctrineSchemaManager($table);
$databasePlatform = $schema->getDatabasePlatform();
$databasePlatform->registerDoctrineTypeMapping('enum', 'string');

$database = null;

if (strpos($table, '.')) {
list($database, $table) = explode('.', $table);
}

return $schema->listTableColumns($table, $database);
} catch (\Throwable $e) {
}

return [];
return \Schema::getColumns($model->getTable());
}

protected function getModelLabel(EloquentModel $model, string $label)
{

$table = '<<table width="100%" height="100%" border="0" margin="0" cellborder="1" cellspacing="0" cellpadding="10">' . PHP_EOL;
$table .= '<tr width="100%"><td width="100%" bgcolor="'.config('erd-generator.table.header_background_color').'"><font color="'.config('erd-generator.table.header_font_color').'">' . $label . '</font></td></tr>' . PHP_EOL;
$table .= '<tr width="100%"><td width="100%" bgcolor="' . config('erd-generator.table.header_background_color') . '"><font color="' . config('erd-generator.table.header_font_color') . '">' . $label . '</font></td></tr>' . PHP_EOL;

if (config('erd-generator.use_db_schema')) {
$columns = $this->getTableColumnsFromModel($model);
foreach ($columns as $column) {
$label = $column->getName();
$label = $column['name'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if array key exists

if (config('erd-generator.use_column_types')) {
$label .= ' ('.$column->getType()->getName().')';
$label .= ' (' . $column['type'] . ')';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if array key exists

}
$table .= '<tr width="100%"><td port="' . $column->getName() . '" align="left" width="100%" bgcolor="'.config('erd-generator.table.row_background_color').'"><font color="'.config('erd-generator.table.row_font_color').'" >' . $label . '</font></td></tr>' . PHP_EOL;
$table .= '<tr width="100%"><td port="' . $label . '" align="left" width="100%" bgcolor="' . config('erd-generator.table.row_background_color') . '"><font color="' . config('erd-generator.table.row_font_color') . '" >' . $label . '</font></td></tr>' . PHP_EOL;
}
}

Expand Down Expand Up @@ -193,7 +176,8 @@ protected function connectBelongsToMany(
);

$this->connectNodes($pivotModelNode, $relatedModelNode, $relation);
} catch (\ReflectionException $e){}
} catch (\ReflectionException $e) {
}
}

/**
Expand Down