Skip to content

Commit

Permalink
Don't insert virtual columns
Browse files Browse the repository at this point in the history
  • Loading branch information
guidocella committed Jul 12, 2017
1 parent f5eeecb commit da43f07
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/GuessesColumnFormatters.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,17 @@ protected function getColumns($model)

list($table, $database) = $this->getTableAndDatabase($model);

return $this->unquoteColumnNames(
$schema->listTableColumns($table, $database),
$platform->getIdentifierQuoteCharacter()
$columns = $model->getConnection()->getDoctrineConnection()->fetchAll(
$platform->getListTableColumnsSQL($table, $database)
);

$columns = $this->rejectVirtualColumns($columns);

$columns = call_user_func(\Closure::bind(function () use ($table, $database, $columns) {
return $this->_getPortableTableColumnList($table, $database, $columns);
}, $schema, $schema));

return $this->unquoteColumnNames($columns, $platform->getIdentifierQuoteCharacter());
}

/**
Expand All @@ -120,6 +127,19 @@ protected function getTableAndDatabase($model)
return [$table, $database];
}

/**
* If the database driver is MySql/MariaDB, filter out any virtual column.
*
* @param array $columns
* @return array The columns.
*/
protected function rejectVirtualColumns(array $columns)
{
return array_filter($columns, function ($column) {
return !isset($column['Extra']) || !str_contains($column['Extra'], 'VIRTUAL');
});
}

/**
* Unquote column names that have been quoted by Doctrine because they are reserved keywords.
*
Expand Down

0 comments on commit da43f07

Please sign in to comment.