mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Bugfix/custom types cause exception (#1228)
* bugfix/custom-types-cause-exception - Added use statements for DBAL Exception and Type - Added @throws tag to getPropertiesFromTable method - Added Type::addType() to properly register types - Added Try-Catch around Type::addType() to give users a proper error message, then throw the exception up. * bugfix/custom-types-cause-exception - Updated CHANGELOG.MD * bugfix/custom-types-cause-exception - Fixed `Type enum_string_boolean already exists.` error from being triggered when multiple models are loaded
This commit is contained in:
@@ -17,6 +17,8 @@ use Barryvdh\Reflection\DocBlock\Context;
|
||||
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
|
||||
use Barryvdh\Reflection\DocBlock\Tag;
|
||||
use Composer\Autoload\ClassMapGenerator;
|
||||
use Doctrine\DBAL\Exception as DBALException;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
@@ -415,6 +417,8 @@ class ModelsCommand extends Command
|
||||
* Load the properties from the database table.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
*
|
||||
* @throws DBALException If custom field failed to register
|
||||
*/
|
||||
public function getPropertiesFromTable($model)
|
||||
{
|
||||
@@ -426,6 +430,14 @@ class ModelsCommand extends Command
|
||||
$platformName = $databasePlatform->getName();
|
||||
$customTypes = $this->laravel['config']->get("ide-helper.custom_db_types.{$platformName}", []);
|
||||
foreach ($customTypes as $yourTypeName => $doctrineTypeName) {
|
||||
try {
|
||||
if(!Type::hasType($yourTypeName)) {
|
||||
Type::addType($yourTypeName, get_class(Type::getType($doctrineTypeName)));
|
||||
}
|
||||
} catch (DBALException $exception) {
|
||||
$this->error("Failed registering custom db type \"$yourTypeName\" as \"$doctrineTypeName\"");
|
||||
throw $exception;
|
||||
}
|
||||
$databasePlatform->registerDoctrineTypeMapping($yourTypeName, $doctrineTypeName);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user