contributte / nextras-orm-generator

:wolf: Rich Nextras\ORM entity generator for fast prototyping your new project.
https://contributte.org/packages/contributte/nextras-orm-generator.html
MIT License
20 stars 14 forks source link

$primary must not be accessed before initialization #37

Open MKI-Miro opened 4 months ago

MKI-Miro commented 4 months ago

Ahojte

Po update na 6.0.1 tu mame novu chybu:

Fatal error: Uncaught Error: Typed property Contributte\Nextras\Orm\Generator\Entity\PhpRelDoc::$primary must not be accessed before initialization in \vendor\contributte\nextras-orm-generator\src\Entity\PhpRelDoc.php:132 Stack trace: #0 \vendor\contributte\nextras-orm-generator\src\Entity\PhpDoc.php(150): Contributte\Nextras\Orm\Generator\Entity\PhpRelDoc->toString() #1 \vendor\contributte\nextras-orm-generator\src\Generator\Entity\Decorator\ColumnDocumentor.php(73): Contributte\Nextras\Orm\Generator\Entity\PhpDoc->toString() #2 \vendor\contributte\nextras-orm-generator\src\Generator\Entity\EntityGenerator.php(60): Contributte\Nextras\Orm\Generator\Generator\Entity\Decorator\ColumnDocumentor->doDecorate(Object(Contributte\Nextras\Orm\Generator\Entity\Column), Object(Nette\PhpGenerator\ClassType), Object(Nette\PhpGenerator\PhpNamespace)) #3 \vendor\contributte\nextras-orm-generator\src\Generator.php(90): Contributte\Nextras\Orm\Generator\Generator\Entity\EntityGenerator->generate(Object(Contributte\Nextras\Orm\Generator\Entity\Database)) #4 \www\nextras.php(20): Contributte\Nextras\Orm\Generator\Generator->generate() #5 {main} thrown in \vendor\contributte\nextras-orm-generator\src\Entity\PhpRelDoc.php on line 132

phpfui commented 4 months ago

Having the same problem in PHP 8.2

Fix is to set the following to null in PhpRelDoc

private ?bool $primary = null;
private ?string $orderProperty = null;
private ?int $orderDirection = null;

I would submit a PR, but I am just benchmarking this ORM and patching the vendor directory gets me around this issue.

Also I would add FQNs to your example or add use statements.

$factory = new \Contributte\Nextras\Orm\Generator\SimpleFactory(
    new \Contributte\Nextras\Orm\Generator\Config\Impl\TogetherConfig($config),
    new \Contributte\Nextras\Orm\Generator\Analyser\Database\DatabaseAnalyser('sqlite:sqlite.db', 'root'));

Thanks for providing this package so I don't have to write code by hand.