beyondcode / beyondcode/invoker-community
Opening Models with enums and other resources gives this errors
- Dominant language
- No language data
- Stars
- 76
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
------
**OS**: darwin
**Invoker Version**: 2.13.2
**Laravel Version**: 9.52.16
**Local project**: true
**PHP Binary**: /opt/local/bin/php
**Route**: /project/index?class=App%5CProject&time=1699447934372&project=local-pRqsxUxr4R3JiW2v2nbauD
**Error**:
```
ErrorException
Undefined array key 1
at phar:/Applications/Invoker.app/Contents/Resources/invoker.phar/src/Factories/AttributeItem.php:39
35▕ public static function getValues(\Illuminate\Database\Eloquent\Model $model, $column)
36▕ {
37▕ $type = $model->getConnection()->select("SHOW COLUMNS FROM `{$model->getTable()}` WHERE Field = '{$column->getName()}'")[0]->Type;
38▕ \preg_match("/^enum\\(\\'(.*)\\'\\)\$/", $type, $matches);
➜ 39▕ $values = \explode("','", $matches[1]);
40▕ return $values;
41▕ }
42▕ public static function getCastFromColumn(\Illuminate\Database\Eloquent\Model $model, $column) : ?string
43▕ {
1 phar:/Applications/Invoker.app/Contents/Resources/invoker.phar/src/Factories/AttributeItem.php:39
Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap\{closure}("Undefined array key 1", "phar:///Applications/Invoker.app/Contents/Resources/invoker.phar/src/Factories/AttributeItem.php")
2 phar:/Applications/Invoker.app/Contents/Resources/invoker.phar/src/Factories/AttributeItem.php:25
_HumbugBoxeb1c6394dc9c\Invoker\Factories\AttributeItem::getValues(Object(App\Project), Object(Doctrine\DBAL\Schema\Column))
```
Probably the reason this is broken is because the query isn't working completely on SingleStore.
The fix is fairly easy in `src/Factories/AttributeItem.php`
```patch
@@ -34,7 +34,7 @@
}
public static function getValues(\Illuminate\Database\Eloquent\Model $model, $column)
{
+ $type = $model->getConnection()->select("SHOW COLUMNS FROM `{$model->getTable()}` LIKE '{$column->getName()}'")[0]->Type;
- $type = $model->getConnection()->select("SHOW COLUMNS FROM `{$model->getTable()}` WHERE Field = '{$column->getName()}'")[0]->Type;
\preg_match("/^enum\\(\\'(.*)\\'\\)\$/", $type, $matches);
$values = \explode("','", $matches[1]);
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.